libis-services 0.1.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) 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/aleph/search.rb +157 -0
  8. data/lib/libis/services/alma/web_service.rb +36 -0
  9. data/lib/libis/services/collective_access/cataloguing.rb +48 -0
  10. data/lib/libis/services/collective_access/connector.rb +151 -0
  11. data/lib/libis/services/collective_access/item_info.rb +36 -0
  12. data/lib/libis/services/collective_access/search.rb +26 -0
  13. data/lib/libis/services/collective_access/service.rb +80 -0
  14. data/lib/libis/services/collective_access.rb +1 -0
  15. data/lib/libis/services/digitool/digital_entity_manager.rb +223 -0
  16. data/lib/libis/services/digitool/digitool_connector.rb +46 -0
  17. data/lib/libis/services/digitool/meta_data_manager.rb +193 -0
  18. data/lib/libis/services/extend/http_fetch.rb +63 -0
  19. data/lib/libis/services/generic_search.rb +38 -0
  20. data/lib/libis/services/http_error.rb +21 -0
  21. data/lib/libis/services/oracle_client.rb +47 -0
  22. data/lib/libis/services/primo/limo.rb +33 -0
  23. data/lib/libis/services/primo/search.rb +46 -0
  24. data/lib/libis/services/primo.rb +2 -0
  25. data/lib/libis/services/rest_client.rb +66 -0
  26. data/lib/libis/services/rosetta/client.rb +108 -0
  27. data/lib/libis/services/rosetta/collection_handler.rb +45 -0
  28. data/lib/libis/services/rosetta/collection_info.rb +44 -0
  29. data/lib/libis/services/rosetta/deposit_activity.rb +48 -0
  30. data/lib/libis/services/rosetta/deposit_handler.rb +187 -0
  31. data/lib/libis/services/rosetta/ie.rb +19 -0
  32. data/lib/libis/services/rosetta/ie_handler.rb +29 -0
  33. data/lib/libis/services/rosetta/oai_pmh.rb +48 -0
  34. data/lib/libis/services/rosetta/oai_set.rb +21 -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 +403 -0
  39. data/lib/libis/services/rosetta/sip.rb +26 -0
  40. data/lib/libis/services/rosetta/sip_handler.rb +31 -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/rosetta.rb +2 -0
  44. data/lib/libis/services/scope/search.rb +46 -0
  45. data/lib/libis/services/search_factory.rb +40 -0
  46. data/lib/libis/services/service_error.rb +16 -0
  47. data/lib/libis/services/sharepoint/connector.rb +236 -0
  48. data/lib/libis/services/sharepoint/search.rb +19 -0
  49. data/lib/libis/services/soap_client.rb +57 -0
  50. data/lib/libis/services/soap_error.rb +22 -0
  51. data/lib/libis/services/version.rb +5 -0
  52. data/lib/libis/services.rb +22 -0
  53. data/lib/libis-services.rb +1 -0
  54. data/libis-services.gemspec +40 -0
  55. data/spec/alma_service_spec.rb +104 -0
  56. data/spec/ie_data.rb +726 -0
  57. data/spec/primo_limo_spec.rb +363 -0
  58. data/spec/primo_search_spec.rb +39 -0
  59. data/spec/rosetta_collection_spec.rb +206 -0
  60. data/spec/rosetta_deposit_spec.rb +82 -0
  61. data/spec/rosetta_ie_spec.rb +54 -0
  62. data/spec/rosetta_oai_spec.rb +52 -0
  63. data/spec/rosetta_pds_spec.rb +79 -0
  64. data/spec/rosetta_producer_spec.rb +270 -0
  65. data/spec/rosetta_sip_spec.rb +39 -0
  66. data/spec/spec_helper.rb +28 -0
  67. metadata +317 -0
@@ -0,0 +1,223 @@
1
+ # coding: utf-8
2
+
3
+ require 'singleton'
4
+
5
+ require 'libis/services/soap_client'
6
+
7
+ #noinspection RubyStringKeysInHashInspection
8
+ module Libis
9
+ module Services
10
+ module Digitool
11
+
12
+ class DigitalEntityManager
13
+ include Singleton
14
+ include Libis::Services::SoapClient
15
+
16
+ def initialize
17
+ setup 'DigitalEntityManager'
18
+ end
19
+
20
+ def create_object(de_info)
21
+ de_call = create_digital_entity_call de_info, 'create'
22
+ request :digital_entity_call, :general => general.to_s, :digital_entity_call => de_call.to_s
23
+ end
24
+
25
+ def update_object(de_info, update_options = {})
26
+ de_call = create_digital_entity_call de_info, 'update', update_options
27
+ request :digital_entity_call, :general => general.to_s, :digital_entity_call => de_call.to_s
28
+ end
29
+
30
+ def delete_object(pid)
31
+ de_info = {'pid' => pid}
32
+ de_options = {'metadata' => 'all', 'relation' => 'all'}
33
+ de_call1 = create_digital_entity_call de_info, 'update', de_options
34
+ result = request :digital_entity_call, :general => 200.to_s, :digital_entity_call => de_call1.to_s
35
+ return result if result[:error] and result[:error].size > 0
36
+ de_call2 = create_digital_entity_call de_info, 'delete'
37
+ request :digital_entity_call, :general => general.to_s, :digital_entity_call => de_call2.to_s
38
+ end
39
+
40
+ def retrieve_object(pid)
41
+ de_info = {'pid' => pid}
42
+ de_call = create_digital_entity_call de_info, 'retrieve'
43
+ request :digital_entity_call, :general => general.to_s, :digital_entity_call => de_call.to_s
44
+ end
45
+
46
+ def link_dc(pid, mid)
47
+ link_md pid, mid, 'descriptive', 'dc'
48
+ end
49
+
50
+ def unlink_dc(pid, mid)
51
+ unlink_md pid, mid, 'descriptive', 'dc'
52
+ end
53
+
54
+ def unlink_all_dc(pid)
55
+ unlink_all_md pid, 'descriptive', 'dc'
56
+ end
57
+
58
+ def link_acl(pid, mid)
59
+ link_md pid, mid, 'accessrights', 'rights_md'
60
+ end
61
+
62
+ def unlink_acl(pid, mid)
63
+ unlink_md pid, mid, 'accessrights', 'rights_md'
64
+ end
65
+
66
+ def unlink_all_acl(pid)
67
+ unlink_all_md pid, 'accessrights', 'rights_md'
68
+ end
69
+
70
+ def link_md(pid, mid, md_name, md_type)
71
+ update_object({'pid' => pid.to_s,
72
+ 'metadata' =>
73
+ [{'cmd' => 'insert',
74
+ 'link_to_exists' => 'true',
75
+ 'mid' => mid.to_s,
76
+ 'name' => md_name,
77
+ 'type' => md_type
78
+ }
79
+ ]
80
+ },
81
+ {'metadata' => 'delta'}
82
+ )
83
+ end
84
+
85
+ def unlink_md(pid, mid, md_name, md_type)
86
+ update_object({'pid' => pid.to_s,
87
+ 'metadata' =>
88
+ [{'cmd' => 'delete',
89
+ 'shared' => 'true',
90
+ 'mid' => mid.to_s,
91
+ 'name' => md_name,
92
+ 'type' => md_type
93
+ }
94
+ ]
95
+ },
96
+ {'metadata' => 'delta'}
97
+ )
98
+ end
99
+
100
+ def unlink_all_md(pid, md_name = nil, md_type = nil)
101
+ de_info = {'pid' => pid.to_s,
102
+ 'metadata' =>
103
+ [{'cmd' => 'delete',
104
+ 'shared' => 'true'
105
+ }
106
+ ]
107
+ }
108
+ de_info['metadata'][0]['name'] = md_name if md_name
109
+ de_info['metadata'][0]['type'] = md_type if md_type
110
+ update_object(de_info, {'metadata' => 'all'})
111
+ end
112
+
113
+ def add_relations(pid, relation_type, related_pids)
114
+ relations = []
115
+ related_pids.each do |p|
116
+ relations << {'cmd' => 'insert',
117
+ 'type' => relation_type.to_s,
118
+ 'pid' => p.to_s
119
+ }
120
+ end
121
+ update_object({'pid' => pid.to_s,
122
+ 'relation' => relations
123
+ },
124
+ {'relation' => 'delta'}
125
+ )
126
+ end
127
+
128
+ def update_stream(pid, filename)
129
+ update_object({'pid' => pid,
130
+ 'stream_ref' =>
131
+ {'cmd' => 'update',
132
+ 'store_command' => 'copy',
133
+ 'location' => 'nfs',
134
+ 'file_name' => filename
135
+ }
136
+ }
137
+ )
138
+ end
139
+
140
+ private
141
+
142
+ def create_digital_entity_call(de_info = {}, command = 'create', update_options = {})
143
+ # de_info is a hash like this:
144
+ # { 'vpid' => 0, || 'pid' => 0,
145
+ # 'control' => { 'label' => 'abc', 'usage_type' => 'archive' },
146
+ # 'metadata' => [ { 'name' => 'descriptive', 'type' => 'dc', 'value' => '<record>...</record>'},
147
+ # { 'cmd' => 'insert', 'link_to_exists' => true, 'mid' => '12345' } ],
148
+ # 'relation' => [ { 'cmd' => 'update', 'type' => 'manifestation', 'pid' => '12345' },
149
+ # { 'cmd' => 'delete', 'type' => 'part_of', pid => '12345' } ],
150
+ # 'stream_ref' => { 'file_name' => 'abc.tif', 'file_extension' => 'tif', ... }
151
+ # }
152
+ # update_options is something like this:
153
+ # { 'metadata' => 'delta',
154
+ # 'relation' => 'all',
155
+ # }
156
+ digital_entity_call = Libis::Tools::XmlDocument.new
157
+ root = digital_entity_call.create_node('digital_entity_call',
158
+ :namespaces => {:node_ns => 'xb',
159
+ 'xb' => 'http://com/exlibris/digitool/repository/api/xmlbeans'})
160
+ digital_entity_call.root = root
161
+
162
+ root << (digital_entity = digital_entity_call.create_node('xb:digital_entity'))
163
+ digital_entity << digital_entity_call.create_text_node('pid', de_info['pid']) if de_info['pid']
164
+ digital_entity << digital_entity_call.create_text_node('vpid', de_info['vpid']) if de_info['vpid']
165
+ if de_info['control']
166
+ digital_entity << (ctrl = digital_entity_call.create_node('control'))
167
+ de_info['control'].each { |k, v| ctrl << digital_entity_call.create_text_node(k.to_s, v.to_s) }
168
+ end
169
+ if de_info['metadata'] || update_options['metadata']
170
+ attributes = {}
171
+ cmd = update_options.delete 'metadata'
172
+ attributes['cmd'] = 'delete_and_insert_' + cmd if cmd
173
+ digital_entity << (mds = digital_entity_call.create_node('mds', :attributes => attributes))
174
+ if de_info['metadata']
175
+ de_info['metadata'].each do |m|
176
+ attributes = {}
177
+ shared = m.delete 'shared'
178
+ attributes['shared'] = shared if shared
179
+ cmd = m.delete 'cmd'
180
+ attributes['cmd'] = cmd if cmd
181
+ link_to_exists = m.delete 'link_to_exists'
182
+ attributes['link_to_exists'] = link_to_exists if link_to_exists
183
+ mds << (md = digital_entity_call.create_node('md', :attributes => attributes))
184
+ m.each { |k, v| md << digital_entity_call.create_text_node(k.to_s, v.to_s) }
185
+ end
186
+ end
187
+ end
188
+ if de_info['relation'] || update_options['relation']
189
+ attributes = {}
190
+ cmd = update_options.delete 'relation'
191
+ attributes['cmd'] = 'delete_and_insert_' + cmd if cmd
192
+ digital_entity << (relations = digital_entity_call.create_node('relations', :attributes => attributes))
193
+ if de_info['relation']
194
+ de_info['relation'].each do |r|
195
+ attributes = {}
196
+ cmd = r.delete 'cmd'
197
+ attributes['cmd'] = cmd if cmd
198
+ relations << (relation = digital_entity_call.create_node('relation', :attributes => attributes))
199
+ r.each { |k, v| relation << digital_entity_call.create_text_node(k.to_s, v.to_s) }
200
+ end
201
+ end
202
+ end
203
+ f = de_info['stream_ref']
204
+ if f
205
+ attributes = {}
206
+ cmd = f.delete 'cmd'
207
+ attributes['cmd'] = cmd if cmd
208
+ store_command = f.delete 'store_command'
209
+ attributes['store_command'] = store_command if store_command
210
+ location = f.delete 'location'
211
+ attributes['location'] = location if location
212
+ digital_entity << (stream_ref = digital_entity_call.create_node('stream_ref', :attributes => attributes))
213
+ de_info['stream_ref'].each { |k, v| stream_ref << digital_entity_call.create_text_node(k.to_s, v.to_s) }
214
+ end
215
+ root << digital_entity_call.create_text_node('command', command)
216
+ digital_entity_call.document
217
+ end
218
+
219
+ end
220
+
221
+ end
222
+ end
223
+ end
@@ -0,0 +1,46 @@
1
+ # coding: utf-8
2
+
3
+ require 'libis/tools/xml_document'
4
+ require 'libis/services/soap_client'
5
+
6
+ module Libis
7
+ module Services
8
+ module Digitool
9
+
10
+ class DigitoolConnector
11
+ include Libis::Services::SoapClient
12
+
13
+ def initialize(service, host = nil)
14
+ @host = host || 'aleph08.libis.kuleuven.be:1801'
15
+ @service = service.to_s.downcase
16
+ end
17
+
18
+ def init
19
+ @base_url = "http://#{@host}/de_repository_web/services/"
20
+ @wsdl_extension = '?wsdl'
21
+ end
22
+
23
+ protected
24
+
25
+ def result_parser(response, options = {})
26
+ result = get_xml_response(response)
27
+ error = nil
28
+ pids = nil
29
+ mids = nil
30
+ de = nil
31
+ doc = Libis::Tools::XmlDocument.parse(result)
32
+ doc.xpath('//error_description').each { |x| error ||= []; error << x.content unless x.content.nil? }
33
+ doc.xpath('//pid').each { |x| pids ||= []; pids << x.content unless x.content.nil? }
34
+ doc.xpath('//mid').each { |x| mids ||= []; mids << x.content unless x.content.nil? }
35
+ doc.xpath('//xb:digital_entity').each { |x| de ||= []; de << x.to_s }
36
+ {errors: error, pids: pids, mids: mids, digital_entities: de}
37
+ end
38
+
39
+ def get_xml_response(response)
40
+ response.first[1][response.first[1][:result].snakecase.to_sym]
41
+ end
42
+
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,193 @@
1
+ # coding: utf-8
2
+
3
+ require 'singleton'
4
+ #require 'iconv'
5
+ #require 'htmlentities'
6
+
7
+ require 'libis/services/soap_client'
8
+
9
+ module Libis
10
+ module Services
11
+ module Digitool
12
+
13
+ # noinspection RubyStringKeysInHashInspection
14
+ class MetaDataManager
15
+ include Singleton, Libis::Services::SoapClient
16
+
17
+ def initialize
18
+ setup 'MetaDataManager'
19
+ end
20
+
21
+ def create_dc(dc)
22
+ dc_string = dc.to_s
23
+ dc_string.force_encoding('UTF-8')
24
+ dc_string.gsub!(/<\?xml[^\?]*\?>(\n)*/x, '')
25
+ dc_string = '<?xml version="1.0" encoding="UTF-8"?>' + dc_string
26
+ # dc_string.gsub!('&','&amp;')
27
+ # dc_string.gsub!('<', '&lt;')
28
+ # dc_string = HTMLEntities.new.encode(dc_string, :named)
29
+ request :create_meta_data_entry, :general => general.to_s, :description => nil, :name => 'descriptive', :type => 'dc', :value => dc_string
30
+ end
31
+
32
+ def create_dc_from_xml(xml_doc)
33
+ create_dc_record_from_xml xml_doc
34
+ end
35
+
36
+ def update_dc(mid, dc)
37
+ request :update_meta_data_entry, :mid => mid.to_s, :general => general.to_s, :description => nil, :name => 'descriptive', :type => 'dc', :value => dc.to_s
38
+ end
39
+
40
+ def create_acl(acl)
41
+ request :create_meta_data_entry, :general => general.to_s, :description => nil, :name => 'accessrights', :type => 'rights_md', :value => acl.to_s
42
+ end
43
+
44
+ def update_acl(mid, acl)
45
+ request :update_meta_data_entry, :mid => mid.to_s, :general => general.to_s, :description => nil, :name => 'accessrights', :type => 'rights_md', :value => acl.to_s
46
+ end
47
+
48
+ def delete(mid)
49
+ request :delete_meta_data_entry, :mid => mid.to_s, :general => general.to_s
50
+ end
51
+
52
+ def retrieve(mid)
53
+ request :retrieve_meta_data_entry, :mid => mid.to_s, :general => general.to_s
54
+ end
55
+
56
+ def create_dc_record_from_xml(xml_doc)
57
+ doc = Libis::Tools::XmlDocument.open xml_doc
58
+ records = doc.xpath('/records/record')
59
+ return nil unless records.size > 0
60
+ create_dc(records[0])
61
+ end
62
+
63
+ def create_dc_record(dc_info)
64
+ doc = Libis::Tools::XmlDocument.new
65
+ doc.root = doc.create_node('record',
66
+ :namespaces => {'dc' => 'http://purl.org/dc/elements/1.1',
67
+ 'dcterms' => 'http://purl.org/dc/terms',
68
+ 'xsi' => 'http://www.w3.org/2001/XMLSchema-instance'})
69
+ if dc_info
70
+ dc_info.each do |k, v|
71
+ doc.root << (n = doc.create_text_node(k.to_s, v.to_s))
72
+ n['xsi:type'] = 'dcterms:URI' if v =~ /^http:\/\//
73
+ end
74
+ end
75
+ doc
76
+ end
77
+
78
+ def create_acl_record(acl_info = nil)
79
+ doc = Libis::Tools::XmlDocument.new
80
+ doc.root = doc.create_node('access_right_md',
81
+ :namespaces => {:node_ns => 'ar',
82
+ 'ar' => 'http://com/exlibris/digitool/repository/api/xmlbeans',
83
+ 'xs' => 'http://www.w3.org/2001/XMLSchema'})
84
+ root = doc.root
85
+ root['enabled'] = 'true'
86
+ return doc unless acl_info
87
+ c = acl_info[:copyright]
88
+ add_acl_copyright(doc, c[:text_file], c[:required]) if c
89
+ e = acl_info[:conditions]
90
+ if e
91
+ e.each do |x|
92
+ add_acl_condition(doc, x[:expressions], x[:negate])
93
+ end
94
+ end
95
+ doc
96
+ end
97
+
98
+ def add_acl_copyright(doc, text_file, required = true)
99
+ root = doc.root
100
+ top = root.xpath('ar_copyrigths')
101
+ if top.empty?
102
+ top = doc.create_node('ar_copyrights')
103
+ root << top
104
+ else
105
+ top = top[0]
106
+ end
107
+ top['required'] = required.to_s if required
108
+ child = top.xpath('text_file')
109
+ child = child.empty? ? doc.create_node('text_file') : top[0]
110
+ child.content = text_file
111
+ top << child
112
+ doc
113
+ end
114
+
115
+ def add_acl_user_group_ip(doc, user, group, iprange, negate = false)
116
+ expressions = []
117
+ user.split.each { |u| expressions << create_acl_expression_user(u) } if user
118
+ group.split.each { |g| expressions << create_acl_expression_group(g) } if group
119
+ iprange.split.each { |i| expressions << create_acl_expression_iprange(i) } if iprange
120
+ add_acl_condition doc, expressions, negate
121
+ end
122
+
123
+ def add_acl_user(doc, user, negate = false)
124
+ expressions = Array.new
125
+ user.split.each { |u| expressions << create_acl_expression_user(u, negate) }
126
+ add_acl_condition doc, expressions
127
+ end
128
+
129
+ def add_acl_group(doc, group, negate = false)
130
+ expressions = Array.new
131
+ group.split.each { |g| expressions << create_acl_expression_group(g, negate) }
132
+ add_acl_condition doc, expressions
133
+ end
134
+
135
+ def add_acl_iprange(doc, iprange, negate = false)
136
+ expressions = Array.new
137
+ iprange.split.each { |i| expressions << create_acl_expression_iprange(i, negate) }
138
+ add_acl_condition doc, expressions
139
+ end
140
+
141
+ def add_acl_condition(doc, expressions, negate = false)
142
+ root = doc.root
143
+ top = root.xpath('ar_conditions')
144
+ if top.empty?
145
+ top = doc.create_node('ar_conditions')
146
+ root << top
147
+ else
148
+ top = top[0]
149
+ end
150
+ top << (cond_node = doc.create_node('ar_condition'))
151
+ cond_node['negate'] = negate.to_s if negate
152
+ cond_node << (exprs_node = doc.create_node('ar_expressions'))
153
+ expressions.each do |e|
154
+ exprs_node << (expr_node = doc.create_node('ar_expression'))
155
+ expr_node['negate'] = e[:negate].to_s if e[:negate]
156
+ expr_node['ar_operation'] = e[:operation].to_s if e[:operation]
157
+ expr_node << doc.create_text_node('key', e[:key].to_s)
158
+ expr_node << doc.create_text_node('val1', e[:val1].to_s)
159
+ expr_node << doc.create_text_node('val2', e[:val2].to_s) if e[:val2]
160
+ end
161
+ doc
162
+ end
163
+
164
+ def create_acl_expression_user(user, negate = false)
165
+ {:operation => 'eq',
166
+ :negate => negate.to_s,
167
+ :key => 'user_id',
168
+ :val1 => user.to_s
169
+ }
170
+ end
171
+
172
+ def create_acl_expression_group(group, negate = false)
173
+ {:operation => 'eq',
174
+ :negate => negate.to_s,
175
+ :key => 'group_id',
176
+ :val1 => group.to_s
177
+ }
178
+ end
179
+
180
+ def create_acl_expression_iprange(iprange, negate = false)
181
+ return nil unless iprange =~ /(\d+\.\d+\.\d+\.\d+)-(\d+\.\d+\.\d+\.\d+)/
182
+ {:operation => 'within',
183
+ :negate => negate.to_s,
184
+ :key => 'ip_range',
185
+ :val1 => $1,
186
+ :val2 => $2
187
+ }
188
+ end
189
+
190
+ end
191
+ end
192
+ end
193
+ end
@@ -0,0 +1,63 @@
1
+ # coding: utf-8
2
+
3
+ require 'net/http'
4
+ require 'set'
5
+
6
+ class Net::HTTPResponse
7
+ #noinspection RubyResolve
8
+ attr_accessor :final_uri
9
+ end
10
+
11
+
12
+ module Net
13
+
14
+ begin
15
+ require 'net/https'
16
+ HTTPS_SUPPORTED = true
17
+ rescue LoadError
18
+ end
19
+
20
+ class HTTP
21
+ def self.fetch(uri, args={}.freeze, &before_fetching)
22
+ uri = URI.parse(uri) unless uri.is_a? URI
23
+ proxy_host = args[:proxy_host]
24
+ proxy_port = args[:proxy_port] || 80
25
+ action = args[:action] || :get
26
+ data = args[:data]
27
+ max_redirects = args[:max_redirects] || 10
28
+
29
+ proxy_class = Proxy(proxy_host, proxy_port)
30
+ #noinspection RubyArgCount
31
+ request = proxy_class.new(uri.host, uri.port)
32
+
33
+ request.use_ssl = true if HTTPS_SUPPORTED && uri.scheme.eql?('https')
34
+
35
+ yield request if block_given?
36
+ #debugger
37
+ response = request.send(action, uri.path, data)
38
+
39
+ urls_seen = args[:_url_seen] || Set.new
40
+
41
+ case response
42
+ when Net::HTTPRedirection
43
+ if urls_seen.size < max_redirects && response['Location']
44
+ urls_seen << uri
45
+ new_uri = URI.parse(response['Location'])
46
+ if urls_seen.member? new_uri
47
+ nil
48
+ else
49
+ new_args = args.dup
50
+ new_args[:_urls_seen] = urls_seen
51
+
52
+ response = HTTP.fetch(new_uri, new_args, &before_fetching)
53
+ end
54
+ end
55
+ when Net::HTTPSuccess
56
+ response.final_uri = uri
57
+ else
58
+ response.error!
59
+ end
60
+ return response
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+
3
+ require 'libis/services/extend/http_fetch'
4
+
5
+ module Libis
6
+ module Services
7
+
8
+ module GenericSearch
9
+
10
+ #noinspection RubyResolve
11
+ attr_accessor :host
12
+ #noinspection RubyResolve
13
+ attr_reader :query, :term, :index, :base
14
+ #noinspection RubyResolve
15
+ attr_reader :num_records, :set_number
16
+ #noinspection RubyResolve
17
+ attr_reader :record_pointer, :session_id
18
+
19
+ def query(query, options = {})
20
+ raise RuntimeError, 'to be implemented'
21
+ end
22
+
23
+ def find(term, options = {})
24
+ query(term, options)
25
+ end
26
+
27
+ def each(options = {}, &block)
28
+ raise RuntimeError, 'to be implemented'
29
+ end
30
+
31
+ def next_record(options = {}, &block)
32
+ raise RuntimeError, 'to be implemented'
33
+ end
34
+
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ module Libis
4
+ module Services
5
+
6
+ class HttpError < Exception
7
+ attr_accessor :code, :header, :body
8
+
9
+ def initialize(error)
10
+ @code = error[:code]
11
+ @header = error[:header]
12
+ @body = error[:body]
13
+ end
14
+
15
+ def message
16
+ code.to_s
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,47 @@
1
+ module Libis
2
+ module Services
3
+
4
+ class OracleClient
5
+
6
+ def initialize(database, user, password)
7
+ @database = database
8
+ @user = user
9
+ @password = password
10
+ end
11
+
12
+ def call(procedure, parameters = [])
13
+ params = ''
14
+ params = "'" + parameters.join("','") + "'" if parameters and parameters.size > 0
15
+ system "echo \"call #{procedure}(#{params});\" | sqlplus -S #{@user}/#{@password}@#{@database}"
16
+ end
17
+
18
+ def run(script, parameters = [])
19
+ params = ''
20
+ params = "\"" + parameters.join("\" \"") + "\"" if parameters and parameters.size > 0
21
+ process_result `sqlplus -S #{@user}/#{@password}@#{@database} @#{script} #{params}`
22
+ end
23
+
24
+ def execute(sql)
25
+ process_result `echo \"#{sql}\" | sqlplus -S #{@user}/#{@password}@#{@database}`
26
+ end
27
+
28
+ private
29
+
30
+ def process_result(log)
31
+ log.gsub!(/\n\n/, "\n")
32
+ rows_created = 0
33
+ log.match(/^(\d+) rows? created.$/) { |m| rows_created += m[1] }
34
+ rows_deleted = 0
35
+ log.match(/^(\d+) rows? deleted.$/) { |m| rows_deleted += m[1] }
36
+ rows_updated = 0
37
+ log.match(/^(\d+) rows? updated.$/) { |m| rows_updated += m[1] }
38
+ errors = Hash.new(0)
39
+ error_count = 0
40
+ log.match(/\nERROR .*\n([^\n]*)\n/) { |m| errors[m[1]] += 1; error_count += 1 }
41
+ {created: rows_created, updated: rows_updated, deleted: rows_deleted, errors: error_count, error_detail: errors}
42
+ end
43
+
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ require 'libis-tools'
3
+
4
+ require 'libis/services/rest_client'
5
+
6
+ module Libis
7
+ module Services
8
+ module Primo
9
+
10
+ class Limo
11
+ include ::Libis::Services::RestClient
12
+
13
+ def initialize(url = 'http://limo.libis.be')
14
+ configure(url)
15
+ end
16
+
17
+ def get_marc(alma_id)
18
+ get 'primo_library/libweb/jqprimo/helpers/record_helper.jsp', id: "#{alma_id}.xml"
19
+ end
20
+
21
+ def get_pnx(alma_id)
22
+ get 'primo_library/libweb/jqprimo/helpers/record_helper.jsp', id: "#{alma_id}.pnx"
23
+ end
24
+
25
+ protected
26
+
27
+ def result_parser(response)
28
+ Libis::Tools::XmlDocument.parse(response)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end