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
@@ -0,0 +1,26 @@
1
+ require 'virtus'
2
+
3
+ module Libis
4
+ module Services
5
+ module Rosetta
6
+ class Sip
7
+ # noinspection RubyResolve
8
+ include Virtus.model nullify_blank: true
9
+
10
+ MODULE = %w'PER'
11
+ STAGE = %w'Finished'
12
+ STATUS = %w'FINISHED'
13
+
14
+ attribute :id, Integer
15
+ attribute :module, String
16
+ attribute :stage, String
17
+ attribute :status, String
18
+
19
+ def to_hash
20
+ super.cleanup
21
+ end
22
+
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+
3
+ require 'libis/tools/extend/hash'
4
+ require_relative 'client'
5
+ require_relative 'sip'
6
+ require_relative 'ie'
7
+
8
+ module Libis
9
+ module Services
10
+ module Rosetta
11
+
12
+ class SipHandler < Libis::Services::Rosetta::Client
13
+
14
+ def initialize(base_url = 'http://depot.lias.be', options = {})
15
+ super 'repository', 'SipWebServices', {url: base_url}.merge(options)
16
+ end
17
+
18
+ def get_info(sip_id)
19
+ request_object :get_sip_status_info, Rosetta::Sip, arg0: sip_id
20
+ end
21
+
22
+ def get_ies(sip_id)
23
+ request_array :get_sip_i_es, arg0: sip_id
24
+ end
25
+
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,70 @@
1
+ require 'virtus'
2
+
3
+ module Libis
4
+ module Services
5
+ module Rosetta
6
+ class User
7
+ # noinspection RubyResolve
8
+ include Virtus.model nullify_blank: true
9
+
10
+ RECORD_TYPE = %w'USER CONTACT ORGANIZATION STAFF PUBLIC'
11
+ USER_STATUS = %w'ACTIVE INACTIVE DELETED'
12
+ USER_ROLES_STATUS = %w'NEW ACTIVE INACTIVE PENDING DELETED'
13
+ USER_TYPE = %w'CASUAL INTERNAL EXTERNAL INTEXTAUTH'
14
+
15
+ attribute :first_name, String
16
+ attribute :last_name, String
17
+ attribute :user_name, String
18
+ attribute :user_group, String
19
+ attribute :expiry_date, String
20
+ attribute :job_title, String
21
+ attribute :default_language, String
22
+ attribute :street, String
23
+ attribute :suburb, String
24
+ attribute :city, String
25
+ attribute :country, String
26
+ attribute :address_1, String
27
+ attribute :address_2, String
28
+ attribute :address_3, String
29
+ attribute :address_4, String
30
+ attribute :address_5, String
31
+ attribute :zip, Integer
32
+ attribute :email_address, String
33
+ attribute :web_site_url, String
34
+ attribute :telephone_1, String
35
+ attribute :telephone_2, String
36
+ attribute :fax, String
37
+
38
+ attribute :password, String
39
+ attribute :password_verify, String
40
+
41
+ def to_hash
42
+ super.cleanup
43
+ end
44
+
45
+ def to_xml
46
+ Libis::Tools::XmlDocument.build do |xml|
47
+ # noinspection RubyResolve
48
+ xml.user_info {
49
+ xml.parent.default_namespace = 'http://www.exlibrisgroup.com/xsd/dps/backoffice/service'
50
+ self.attributes.each do |name, value|
51
+ xml.send(name, xmlns: '') { xml.text(value) } if value
52
+ end
53
+ }
54
+ end.to_xml
55
+ end
56
+
57
+ def self.from_xml(xml)
58
+ xml_doc = Libis::Tools::XmlDocument.parse(xml)
59
+ hash = xml_doc.to_hash(
60
+ strip_namespaces: true,
61
+ delete_namespace_attributes: true,
62
+ empty_tag_value: nil,
63
+ convert_tags_to: lambda { |tag| tag.to_sym }
64
+ )
65
+ self.new(hash[:producer_info])
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+ require 'virtus'
3
+
4
+ require 'libis/tools/extend/hash'
5
+ require_relative 'client'
6
+
7
+ module Libis
8
+ module Services
9
+ module Rosetta
10
+
11
+ class UserManager < Libis::Services::Rosetta::Client
12
+
13
+ def initialize(base_url = 'http://depot.lias.be', options = {})
14
+ super 'infra', 'UserManagerWS', {url: base_url}.merge(options)
15
+ end
16
+
17
+ def user(user_id, user_info)
18
+ user_info = user_info.to_hash if user_info.is_a? User
19
+ do_request :update_user, arg0: user_info, arg1: user_id
20
+ end
21
+
22
+ protected
23
+
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,46 @@
1
+ # coding: utf-8
2
+
3
+ require 'libis/services/oracle_client'
4
+ require 'libis/tools/xml_document'
5
+
6
+ module Libis
7
+ module Services
8
+ module Scope
9
+
10
+ class Search
11
+ include ::Libis::Services::GenericSearch
12
+
13
+ def initialize
14
+ @doc = nil
15
+ end
16
+
17
+ def find(term, options = {})
18
+ super
19
+ OracleClient.new('SCOPE01', 'APLKN_ARCHV_LIAS', 'archvsc').
20
+ call('kul_packages.scope_xml_meta_file_ed', [term.upcase])
21
+ err_file = "/nas/vol03/oracle/scope01/#{term}_err.XML"
22
+ if File.exist? err_file
23
+ doc = XmlDocument.open(err_file)
24
+ msg = doc.xpath('/error/error_msg').first.content
25
+ msg_detail = doc.xpath('/error/error_').first.content
26
+ File.delete(err_file)
27
+ @doc = nil
28
+ raise RuntimeError, "Scope search failed: '#{msg}'. Details: '#{msg_detail}'"
29
+ else
30
+ @doc = XmlDocument.open("/nas/vol03/oracle/scope01/#{term}_md.XML").to_hash
31
+ end
32
+ end
33
+
34
+ def each(_ = {})
35
+ yield @doc
36
+ end
37
+
38
+ def next_record(_ = {})
39
+ yield @doc
40
+ end
41
+
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,40 @@
1
+ # coding: utf-8
2
+
3
+ require_relative 'aleph/search'
4
+ require_relative 'primo/search'
5
+ require_relative 'sharepoint/search'
6
+ require_relative 'scope/search'
7
+
8
+ module Libis
9
+ module Services
10
+
11
+ class SearchFactory
12
+ def initialize(format, *args)
13
+ @search_class = self.class.const_get("Libis::Services::#{format}::Search")
14
+ @search_client = @search_class.new *args
15
+
16
+ rescue Exception => e
17
+ puts e.message
18
+ exit -1
19
+ end
20
+
21
+ def query(query, options = {})
22
+ @search_client.get(query, options)
23
+ end
24
+
25
+ def find(term, options = {})
26
+ @search_client.find(term, options)
27
+ end
28
+
29
+ def each(options = {}, &block)
30
+ @search_client.each(options, &block)
31
+ end
32
+
33
+ def next_record(options = {}, &block)
34
+ @search_client.next_record(options, &block)
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,236 @@
1
+ # coding: utf-8
2
+
3
+ require 'highline'
4
+ require 'libis/tools/logger'
5
+
6
+ require 'libis/services/soap_client'
7
+
8
+ module Libis
9
+ module Services
10
+ module Sharepoint
11
+
12
+ class Search
13
+ include ::Libis::Services::SoapClient
14
+ include ::Libis::Tools::Logger
15
+ include ::Libis::Services::GenericSearch
16
+
17
+ private
18
+
19
+ MY_QUERY_SYMBOLS = {
20
+ nil => 'Eq',
21
+ '==' => 'Eq',
22
+ '!=' => 'Neq',
23
+ '>' => 'Gt',
24
+ '>=' => 'Geq',
25
+ '<' => 'Lt',
26
+ '<=' => 'Leq',
27
+ 'is null' => 'IsNull'
28
+ }
29
+
30
+ MAX_QUERY_RETRY = 10
31
+
32
+ public
33
+
34
+ def initialize(options = {})
35
+ options[:server_url] = (options[:url] || 'https://www.groupware.kuleuven.be/sites/lias') + (options[:url_ext] || '/_vti_bin')
36
+ options[:ssl] = true if options[:server_url] =~ /^https:/
37
+ # options[:soap_url] = options[:server_url].gsub(/^(https?):\/\/)/,"\\1#{CGI.escape(username)}:#{CGI.escape(password)}@") + '/Lists.asmx'
38
+ options[:wsse_auth] = [options[:username], options[:password]]
39
+ options[:soap_url] = options[:server_url] + '/Lists.asmx'
40
+ options[:wsdl_url] = options[:soap_url] + '?wsdl'
41
+ configure options[:wsdl_url], options
42
+ options
43
+ end
44
+
45
+ def query(term, options = {})
46
+
47
+ options[:term] = term
48
+
49
+ options[:limit] ||= 100
50
+ options[:value_type] ||= 'Text'
51
+ options[:query_operator] = MY_QUERY_SYMBOLS[options[:query_operator] || '==']
52
+
53
+ options[:query_operator] = 'BeginsWith' if term =~ /^[^*]+\*$/
54
+ options[:query_operator] = 'Contains' if term =~ /^\*[^*]+\*$/
55
+
56
+ restart_query options
57
+
58
+ options
59
+
60
+ end
61
+
62
+ def each(options)
63
+
64
+ # we start with a new search
65
+ restart_query options
66
+ get_next_set options
67
+
68
+ while records_to_process? options
69
+
70
+ yield options[:result][:records][options[:current]]
71
+
72
+ options[:current] += 1
73
+
74
+ get_next_set(options) if require_next_set?(options)
75
+
76
+ end
77
+
78
+ restart_query(options)
79
+
80
+ end
81
+
82
+ protected
83
+
84
+ def restart_query(options)
85
+ options[:start_id] = 0
86
+ options[:result] = nil
87
+ options[:current] = 0
88
+ options[:set_count] = 0
89
+ options[:next_set] = nil
90
+ end
91
+
92
+ def records_to_process?(options)
93
+ options[:current] < options[:set_count]
94
+ end
95
+
96
+ def require_next_set?(options)
97
+ options[:current] >= options[:set_count] and options[:next_set]
98
+ end
99
+
100
+ def get_next_set(options)
101
+
102
+ options[:current] = 0
103
+ options[:set_count] = 0
104
+
105
+ retry_count = MAX_QUERY_RETRY
106
+
107
+ while retry_count > 0
108
+
109
+ warn "Retrying (#{retry_count}) ..." if retry_count < MAX_QUERY_RETRY
110
+
111
+ query = {
112
+ 'Query' => {
113
+ 'Where' => {
114
+ options[:query_operator] => {
115
+ 'FieldRef' => '',
116
+ 'Value' => options[:term],
117
+ :attributes! => {
118
+ 'FieldRef' => {
119
+ 'Name' => options[:index]
120
+ },
121
+ 'Value' => {
122
+ 'Type' => options[:value_type]
123
+ }
124
+ }
125
+ }
126
+ }
127
+ }
128
+ }
129
+
130
+ query_options = {
131
+ 'QueryOptions' => {
132
+ 'ViewAttributes' => '',
133
+ :attributes! => {
134
+ 'ViewAttributes' => {
135
+ 'Scope' => 'RecursiveAll'
136
+ }
137
+ }
138
+ }
139
+ }
140
+
141
+ now = Time.now
142
+ window_start = Time.new(now.year, now.month, now.day, 12, 15)
143
+ window_end = Time.new(now.year, now.month, now.day, 13, 15)
144
+ if options[:selection] and now > window_start and now < window_end
145
+ query_options['QueryOptions']['Folder'] = options[:server_url] + 'Gedeelde%20documenten/' + options[:selection] + '/.'
146
+ end
147
+
148
+ if options[:next_set]
149
+ query_options['QueryOptions']['Paging'] = ''
150
+ query_options['QueryOptions'][:attributes!]['Paging'] = {'ListItemCollectionPositionNext' => options[:next_set]}
151
+ end
152
+
153
+ result = request 'GetListItems', {
154
+ soap_options: {
155
+ endpoint: options[:soap_url]
156
+ },
157
+ wsse_auth: options[:wsse_auth],
158
+ listName: options[:base],
159
+ viewName: '',
160
+ query: query,
161
+ viewFields: {'ViewFields' => ''},
162
+ rowLimit: options[:limit].to_s,
163
+ query_options: query_options,
164
+ webID: ''
165
+ }, {}, options
166
+
167
+ if result[:error]
168
+ warn "SOAP error: '#{result[:error]}'"
169
+ raise RuntimeError, 'Too many SOAP errors, giving up.' unless retry_count > 0
170
+ elsif result[:exception]
171
+ warn "SOAP exception: '#{result[:exception].message}'"
172
+ raise result[:exception] unless retry_count > 0
173
+ else
174
+ options[:result] = result
175
+ options[:set_count] = result[:count]
176
+ options[:next_set] = result[:next_set]
177
+ retry_count = 0
178
+ retry_count = MAX_QUERY_RETRY + 1 if options[:set_count] == 0 and options[:next_set]
179
+ end
180
+
181
+ retry_count -= 1
182
+
183
+ end
184
+
185
+ end
186
+
187
+ def result_parser(result, options)
188
+
189
+ records = []
190
+ result = result[:get_list_items_response][:get_list_items_result]
191
+
192
+ data = result[:listitems][:data]
193
+
194
+ rows = data[:row]
195
+ rows = [rows] unless rows.is_a? Array
196
+
197
+ rows.each do |row|
198
+ if options[:selection].nil? or row[:ows_FileRef] =~ /^\d+;#sites\/lias\/Gedeelde documenten\/#{options[:selection]}(|\/.*)$/
199
+ records << clean_row(row, options)
200
+ end
201
+ end
202
+
203
+ next_set = data[:@list_item_collection_position_next]
204
+
205
+ # the itemcount in the response is not interesting. We count only the records that match our selection criteria.
206
+ count = records.size
207
+
208
+ {next_set: next_set, records: records, count: count}
209
+
210
+ end
211
+
212
+ def clean_row(row, options)
213
+
214
+ options[:fields_found] ||= Set.new
215
+ row.keys.each { |k| options[:fields_found] << k }
216
+
217
+ fields_to_be_removed = [:ows_MetaInfo]
218
+ fields_to_be_removed = row.keys - options[:field_selection] if options[:field_selection]
219
+
220
+ record = SharepointRecord.new
221
+
222
+ row.each do |k, v|
223
+ key = k.to_s.gsub(/^@/, '').to_sym
224
+ next if fields_to_be_removed.include? key
225
+ record[key] = v.dot_net_clean
226
+ end
227
+
228
+ record
229
+
230
+ end
231
+
232
+ end
233
+
234
+ end
235
+ end
236
+ end