libis-services 0.1.0-java

Sign up to get free protection for your applications and to get access to all the features.
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,60 @@
1
+ # encoding: utf-8
2
+
3
+ require 'libis/services/rest_client'
4
+
5
+ module Libis
6
+ module Services
7
+ module Rosetta
8
+
9
+ class PdsHandler
10
+ include Libis::Services::RestClient
11
+
12
+ # @param [String] base_url
13
+ def initialize(base_url = 'https://pds.libis.be')
14
+ configure base_url
15
+ end
16
+
17
+ # @param [String] user
18
+ # @param [String] password
19
+ # @param [String] institute
20
+ # @return [String] PDS handle, nil if could not login
21
+ def login(user, password, institute)
22
+ params = {
23
+ func: 'login-url',
24
+ bor_id: user,
25
+ bor_verification: password,
26
+ institute: institute
27
+ }
28
+ response = get 'pds', params
29
+ return nil unless response.code == 200 and response.body.match /pds_handle=(\d+)[^\d]/
30
+ $1
31
+ end
32
+
33
+ # @param [String] pds_handle
34
+ # @return [Boolean] true if success
35
+ def logout(pds_handle)
36
+ params = {
37
+ func: 'logout',
38
+ pds_handle: pds_handle
39
+ }
40
+ response = get 'pds', params
41
+ response.code == 200
42
+ end
43
+
44
+ # @param [String] pds_handle
45
+ # @return [Hash] with user information. At least containing: 'id', 'name', 'institute' and 'group'
46
+ def user_info(pds_handle)
47
+ params = {
48
+ func: 'get-attribute',
49
+ attribute: 'BOR_INFO',
50
+ pds_handle: pds_handle
51
+ }
52
+ response = get 'pds', params
53
+ return nil unless response.code == 200
54
+ Nori.new(convert_tags_to: lambda {|tag| tag.to_sym}).parse(response.body)
55
+ end
56
+ end
57
+
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,71 @@
1
+ require 'virtus'
2
+
3
+ module Libis
4
+ module Services
5
+ module Rosetta
6
+ class Producer
7
+ # noinspection RubyResolve
8
+ include Virtus.model(nullify_blank: true)
9
+
10
+ attribute :authoritative_name, String, default: 'producer'
11
+ attribute :account_type, String, default: 'GROUP'
12
+ attribute :status, String, default: 'ACTIVE'
13
+ attribute :expiry_date, String
14
+ attribute :first_name, String
15
+ attribute :last_name, String
16
+ attribute :institution, String, default: 'institution'
17
+ attribute :department, String, default: 'department'
18
+ attribute :user_name, String
19
+ attribute :producer_group, String, default: 'Published'
20
+ attribute :negotiator_id, String
21
+ attribute :producerProfile_id, String
22
+ attribute :telephone_1, String
23
+ attribute :telephone_2, String
24
+ attribute :fax, String
25
+ attribute :email, String
26
+ attribute :email_notify, String
27
+ attribute :web_site, String
28
+ attribute :street, String
29
+ attribute :suburb, String
30
+ attribute :city, String
31
+ attribute :zip_code, String
32
+ attribute :country, String
33
+ attribute :notes, String
34
+ attribute :local_field_1, String
35
+ attribute :local_field_2, String
36
+ attribute :contactUser_id_1, String
37
+ attribute :contactUser_id_2, String
38
+ attribute :contactUser_id_3, String
39
+ attribute :contactUser_id_4, String
40
+ attribute :contactUser_id_5, String
41
+
42
+ def to_hash
43
+ attributes.cleanup
44
+ end
45
+
46
+ def to_xml
47
+ Libis::Tools::XmlDocument.build do |xml|
48
+ # noinspection RubyResolve
49
+ xml.producer_info {
50
+ xml.parent.default_namespace = 'http://www.exlibrisgroup.com/xsd/dps/backoffice/service'
51
+ self.attributes.each do |name, value|
52
+ xml.send(name, xmlns: '').text(value) if value
53
+ end
54
+ }
55
+ end.to_xml
56
+ end
57
+
58
+ def self.from_xml(xml)
59
+ xml_doc = Libis::Tools::XmlDocument.parse(xml)
60
+ hash = xml_doc.to_hash(
61
+ strip_namespaces: true,
62
+ delete_namespace_attributes: true,
63
+ empty_tag_value: nil,
64
+ convert_tags_to: lambda { |tag| tag.to_sym }
65
+ )
66
+ self.new(hash[:producer_info])
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,125 @@
1
+ # encoding: utf-8
2
+ require 'libis/tools/extend/hash'
3
+ require 'libis/tools/xml_document'
4
+ require_relative 'producer'
5
+ require_relative 'user'
6
+
7
+ require_relative 'client'
8
+ module Libis
9
+ module Services
10
+ module Rosetta
11
+
12
+ class ProducerHandler < Libis::Services::Rosetta::Client
13
+
14
+
15
+ def initialize(base_url = 'http://depot.lias.be', options = {})
16
+ super 'backoffice', 'ProducerWebServices', {url: base_url}.merge(options)
17
+ end
18
+
19
+ def user_id(external_id)
20
+ call :get_internal_user_id_by_external_id, arg0: external_id
21
+ end
22
+
23
+ def is_user?(user_id)
24
+ call :is_user_exists, arg0: @pds_handle, arg1: user_id
25
+ end
26
+
27
+ def producer(producer_id, producer_info = nil)
28
+ if producer_info
29
+ info = producer(producer_id)
30
+ return nil if info.nil?
31
+ (producer_info.is_a?(Rosetta::Producer) ? producer_info.attributes : producer_info).each do |name, value|
32
+ info[name] = value
33
+ end
34
+ call :update_producer, arg0: @pds_handle, arg1: producer_id, arg2: info.to_xml
35
+ else
36
+ request_object :get_producer_details, Rosetta::Producer, arg0: @pds_handle, arg1: producer_id
37
+ end
38
+ end
39
+
40
+ def new_producer(producer_info)
41
+ producer_info = Rosetta::Producer.new(producer_info) unless producer_info.is_a?(Rosetta::Producer)
42
+ call :create_producer, arg0: @pds_handle, arg1: producer_info.to_xml
43
+ end
44
+
45
+ def delete_producer(producer_id)
46
+ call :remove_producer, arg0: @pds_handle, arg1: producer_id
47
+ end
48
+
49
+ def agent(agent_id, agent_info = nil)
50
+ if agent_info
51
+ info = agent(agent_id)
52
+ return nil if info.nil?
53
+ (agent_info.is_a?(Rosetta::User) ? agent_info.attributes : agent_info).each do |name, value|
54
+ info[name] = value
55
+ end
56
+ call :update_producer_agent, arg0: @pds_handle, arg1: agent_id, arg2: info.to_xml
57
+ else
58
+ request_object :get_producer_agent, Rosetta::User, arg0: @pds_handle, arg1: agent_id
59
+ end
60
+ end
61
+
62
+ def new_agent(agent_info)
63
+ agent_info = Rosetta::User.new(agent_info) unless agent_info.is_a?(Rosetta::User)
64
+ call :create_producer_agent, arg0: @pds_handle, arg1: agent_info.to_xml
65
+ end
66
+
67
+ def delete_agent(agent_id)
68
+ call :remove_producer_agent, arg0: @pds_handle, arg1: agent_id
69
+ end
70
+
71
+ def link_agent(agent_id, producer_id)
72
+ call :link_producer_agent_to_producer, arg0: @pds_handle, arg1: producer_id, arg2: agent_id
73
+ end
74
+
75
+ def unlink_agent(agent_id, producer_id)
76
+ call :unlink_producer_agent_from_producer, arg0: @pds_handle, arg1: producer_id, arg2: agent_id
77
+ end
78
+
79
+ def agent_producers(agent_id, institution = nil)
80
+ if institution
81
+ request_array :get_producers_of_producer_agent_with_ins, arg0: agent_id, arg1: institution
82
+ else
83
+ request_array :get_producers_of_producer_agent, arg0: agent_id
84
+ end
85
+ end
86
+
87
+ def contact(contact_id, contact_info = nil)
88
+ if contact_info
89
+ info = contact(contact_id)
90
+ return nil if info.nil?
91
+ (contact_info.is_a?(Rosetta::User) ? contact_info.attributes : contact_info).each do |name, value|
92
+ info[name] = value
93
+ end
94
+ call :update_contact, arg0: @pds_handle, arg1: contact_id, arg2: info.to_xml
95
+ else
96
+ request_object :get_contact, Rosetta::User, arg0: @pds_handle, arg1: contact_id
97
+ end
98
+ end
99
+
100
+ def new_contact(contact_info)
101
+ contact_info = Rosetta::User.new(contact_info) unless contact_info.is_a?(Rosetta::User)
102
+ call :create_contact, arg0: @pds_handle, arg1: contact_info.to_xml
103
+ end
104
+
105
+ def delete_contact(contact_id)
106
+ call :remove_contact, arg0: @pds_handle, arg1: contact_id
107
+ end
108
+
109
+ def link_contact(contact_id, producer_id, primary = true)
110
+ call :link_contact_to_producer, arg0: @pds_handle, arg1: producer_id, arg2: contact_id, arg3: (!!primary).to_s.upcase
111
+ end
112
+
113
+ def unlink_contact(contact_id, producer_id)
114
+ call :unlink_contact_from_producer, arg0: @pds_handle, arg1: producer_id, arg2: contact_id
115
+ end
116
+
117
+ def material_flows(producer_id)
118
+ request_array :get_material_flows_of_producer, arg0: producer_id
119
+ end
120
+
121
+ end
122
+
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,403 @@
1
+ require_relative 'pds_handler'
2
+ require_relative 'producer_handler'
3
+ require_relative 'deposit_handler'
4
+ require_relative 'sip_handler'
5
+ require_relative 'ie_handler'
6
+ require_relative 'collection_handler'
7
+ require_relative 'oai_pmh'
8
+
9
+ require 'libis/tools/mets_file'
10
+
11
+ require 'csv'
12
+ require 'write_xlsx'
13
+ require 'backports'
14
+ require 'awesome_print'
15
+
16
+ module Libis
17
+ module Services
18
+ module Rosetta
19
+
20
+ # noinspection RubyTooManyInstanceVariablesInspection
21
+ class Service
22
+
23
+ attr_reader :pds_service, :producer_service, :deposit_service, :sip_service, :ie_service, :collection_service
24
+
25
+ # @param [String] base_url
26
+ def initialize(base_url = 'http://depot.lias.be', pds_url = 'https://pds.libis.be', opts = {})
27
+ @pds_service = Libis::Services::Rosetta::PdsHandler.new pds_url
28
+ @producer_service = Libis::Services::Rosetta::ProducerHandler.new base_url, opts
29
+ @deposit_service = Libis::Services::Rosetta::DepositHandler.new base_url, opts
30
+ @sip_service = Libis::Services::Rosetta::SipHandler.new base_url, opts
31
+ @ie_service = Libis::Services::Rosetta::IeHandler.new base_url, opts
32
+ @collection_service = Libis::Services::Rosetta::CollectionHandler.new base_url, opts
33
+ @oai_pmh_service = Libis::Services::Rosetta::OaiPmh.new base_url, opts
34
+ end
35
+
36
+ # @param [String] name
37
+ # @param [String] passwd
38
+ # @param [String] institute
39
+ # @return [String] PDS handle
40
+ def login(name, passwd, institute)
41
+ handle = @pds_service.login(name, passwd, institute)
42
+ @producer_service.pds_handle = handle
43
+ @deposit_service.pds_handle = handle
44
+ @sip_service.pds_handle = handle
45
+ @ie_service.pds_handle = handle
46
+ @collection_service.pds_handle = handle
47
+ handle
48
+ end
49
+
50
+ # Searches for all deposits in the date range and for the given flow id. The method returns a list of all
51
+ # deposits, including information about the sip, the related IEs and a breakdown of the IE's METS file.
52
+ #
53
+ # @param [String] from_date
54
+ # @param [String] to_date
55
+ # @param [String] flow_id
56
+ # @param [String] options
57
+ # @return [Hash] detailed deposit information
58
+ def get_deposits(from_date, to_date, flow_id, options = {})
59
+ deposits = @deposit_service.get_by_submit_flow(from_date, to_date, flow_id, {status: 'Approved'}.merge(options))
60
+ deposits.each do |deposit|
61
+ ies = @sip_service.get_ies(deposit[:sip])
62
+ ies_info = ies.map do |ie|
63
+ title = nil
64
+ id = nil
65
+ begin
66
+ md = @ie_service.get_metadata(ie).to_hash['mets:mets']
67
+ dc = md['mets:dmdSec']['mets:mdWrap']['mets:xmlData']['dc:record']
68
+ title = dc['dc:title']
69
+ id = dc['dc:identifier']
70
+ rescue
71
+ # ignore
72
+ end
73
+ # retrieve ie mets file
74
+ ie_info = @ie_service.get_mets(ie)
75
+ {
76
+ ie: ie,
77
+ title: title,
78
+ id: id,
79
+ content: ie_info
80
+ }.cleanup
81
+ end
82
+ deposit[:ies] = ies_info
83
+ end
84
+ deposits.sort! { |x, y| x[:ies][0][:id] <=> y[:ies][0][:id] }
85
+ # deposits.each { |dep| dep[:ies].each { |ie| puts "DEP ##{dep[:deposit]} - SIP ##{dep[:sip]} - IE ##{ie[:ie]} - #{ie[:id]} - #{ie[:title]}" } }
86
+ deposits
87
+ end
88
+
89
+ # @param [String] report_file
90
+ # @param [Array] deposits
91
+ def get_deposit_report(report_file, deposits)
92
+ # create and open Workbook
93
+ workbook = WriteXLSX.new(report_file)
94
+
95
+ # set up some formatting
96
+ ie_data_header_format = workbook.add_format(bold: 1)
97
+ rep_name_format = workbook.add_format(bold: 1)
98
+ file_header_format = workbook.add_format(bold: 1)
99
+
100
+ # First Sheet is an overview of all dossiers
101
+ overview = workbook.add_worksheet('IE overview')
102
+ ie_data_keys = Set.new %w[id dossier link disposition]
103
+ ie_list = [] # ie info will be collected in this array to be printed later
104
+
105
+ # iterate over all deposits
106
+ deposits.each do |deposit|
107
+ # iterate over all IEs
108
+ deposit[:ies].sort { |x, y| x[:id] <=> y[:id] }.each do |ie|
109
+ @ie = ie
110
+ id = (ie[:id] || ie[:ie])
111
+ # noinspection RubyStringKeysInHashInspection
112
+ ie_data = {
113
+ 'id' => "#{id}",
114
+ 'dossier' => ie[:title],
115
+ 'disposition' => (ie[:content][:dmd]['date'] rescue nil),
116
+ 'link' => "http://depot.lias.be/delivery/DeliveryManagerServlet?dps_pid=#{ie[:ie]}",
117
+ }.cleanup
118
+ [
119
+ # (ie[:content][:dmd] rescue nil),
120
+ (ie[:content][:amd][:tech]['generalIECharacteristics'] rescue nil),
121
+ (ie[:content][:amd][:rights]['accessRightsPolicy'] rescue nil)
122
+ ].each do |data|
123
+ ie_data.merge! data if data
124
+ end
125
+ dossier_sheet = workbook.add_worksheet(id.gsub(/[\\\/*?]+/, '.'))
126
+ dossier_row = 0
127
+
128
+ ie[:content].each do |rep_name, rep|
129
+ next unless rep_name.is_a?(String)
130
+ @rep = rep
131
+ file_data_keys = Set.new %w(folder naam link mimetype puid formaat versie)
132
+ file_list = []
133
+
134
+ dossier_sheet.write_row(dossier_row, 0, [rep_name], rep_name_format)
135
+ %w(preservationType usageType).each do |key|
136
+ dossier_row += 1
137
+ dossier_sheet.write_row(
138
+ dossier_row, 0,
139
+ [
140
+ key.underscore.gsub('_', ' '),
141
+ rep[:amd][:tech]['generalRepCharacteristics'][key]
142
+ ]
143
+ )
144
+ end
145
+ dossier_row += 2
146
+
147
+ file_proc = lambda do |file|
148
+ @file = file
149
+ if file[:id]
150
+ tech = file[:amd][:tech]
151
+ # noinspection RubyStringKeysInHashInspection
152
+ file_data = {
153
+ 'folder' => (tech['generalFileCharacteristics']['fileOriginalPath'] rescue '').split('/')[1..-1].join('\\'),
154
+ 'naam' => (tech['generalFileCharacteristics']['fileOriginalName'] rescue nil),
155
+ 'link' => ("http://depot.lias.be/delivery/DeliveryManagerServlet?dps_pid=#{file[:id]}" rescue nil),
156
+ 'mimetype' => (tech['fileFormat']['mimeType'] rescue nil),
157
+ 'puid' => (tech['fileFormat']['formatRegistryId'] rescue nil),
158
+ 'formaat' => (tech['fileFormat']['formatDescription'] rescue nil),
159
+ 'versie' => (tech['fileFormat']['formatVersion'] rescue nil),
160
+ 'viruscheck' => (tech['fileVirusCheck']['status'] rescue nil),
161
+ 'file_type' => (tech['generalFileCharacteristics']['FileEntityType']),
162
+ 'groep' => file[:group],
163
+ }
164
+ data = tech['fileValidation']
165
+ if data
166
+ valid = (data['isValid'] == 'true') rescue nil
167
+ well_formed = (data['isWellFormed'] == 'true') rescue nil
168
+ file_data['validatie'] = if valid && well_formed
169
+ 'OK'
170
+ else
171
+ 'niet OK'
172
+ end
173
+ end
174
+ data = tech['significantProperties']
175
+ if data
176
+ file_data[data['significantPropertiesType']] = data['significantPropertiesValue']
177
+ end
178
+ data = file[:dmd]
179
+ if data
180
+ data.each { |key, value| file_data[key] = value }
181
+ end
182
+ file_list << file_data
183
+ file_data_keys.merge file_data.keys
184
+ else
185
+ file.each do |_, value|
186
+ next unless value.is_a? Hash
187
+ # noinspection RubyScope
188
+ file_proc.call(value)
189
+ end
190
+ end
191
+ end
192
+
193
+ rep.keys.each do |key|
194
+ file_proc.call(rep[key]) if key.is_a?(String)
195
+ end
196
+
197
+ table_start = dossier_row
198
+ dossier_sheet.write_row(dossier_row, 0, file_data_keys.to_a, file_header_format)
199
+ file_list.each do |file_info|
200
+ dossier_row += 1
201
+ file_data = []
202
+ file_data_keys.each { |key| file_data << file_info[key] }
203
+ dossier_sheet.write_row(dossier_row, 0, file_data)
204
+ end
205
+ table_end = dossier_row
206
+
207
+ dossier_sheet.add_table(
208
+ table_start, 0, table_end, file_data_keys.size - 1,
209
+ style: 'Table Style Medium 16', name: rep[:id],
210
+ columns: file_data_keys.map { |key| {header: key} }
211
+ )
212
+
213
+ dossier_row += 2
214
+ end
215
+ ie_data_keys.merge ie_data.keys
216
+ ie_list << ie_data
217
+ end
218
+ end
219
+
220
+ # write ie data to overview worksheet
221
+ overview.write_row(0, 0, ie_data_keys.to_a, ie_data_header_format)
222
+ overview_row = 1
223
+ ie_list.each do |ie_info|
224
+ ie_data = []
225
+ ie_data_keys.each { |key| ie_data << ie_info[key] }
226
+ overview.write_row(overview_row, 0, ie_data)
227
+ overview_row += 1
228
+ end
229
+
230
+ rescue Exception => e
231
+ puts e.message
232
+ puts e.backtrace
233
+ # close and save workbook
234
+ ensure
235
+ workbook.close
236
+ end
237
+
238
+ # @param [String] report_file
239
+ # @param [Array] deposits
240
+ def get_dav_deposit_report(report_file, deposits)
241
+ # create and open Workbook
242
+ workbook = WriteXLSX.new(report_file)
243
+
244
+ # set up some formatting
245
+ ie_data_header_format = workbook.add_format(bold: 1)
246
+ rep_name_format = workbook.add_format(bold: 1)
247
+ file_header_format = workbook.add_format(bold: 1)
248
+
249
+ # First Sheet is an overview of all dossiers
250
+ overview = workbook.add_worksheet('dossier overzicht')
251
+ ie_data_keys = Set.new %w[id dossier link disposition]
252
+ ie_list = [] # ie info will be collected in this array to be printed later
253
+
254
+ # iterate over all deposits
255
+ deposits.each do |deposit|
256
+ # iterate over all IEs
257
+ deposit[:ies].sort { |x, y| x[:id] <=> y[:id] }.each do |ie|
258
+ @ie = ie
259
+ id = (ie[:id] || ie[:ie])
260
+ # noinspection RubyStringKeysInHashInspection
261
+ ie_data = {
262
+ 'id' => "#{id}",
263
+ 'dossier' => ie[:title],
264
+ 'disposition' => (ie[:content][:dmd]['date'] rescue nil),
265
+ 'link' => "http://depot.lias.be/delivery/DeliveryManagerServlet?dps_pid=#{ie[:ie]}",
266
+ }.cleanup
267
+ [
268
+ # (ie[:content][:dmd] rescue nil),
269
+ (ie[:content][:amd][:tech]['generalIECharacteristics'] rescue nil),
270
+ (ie[:content][:amd][:rights]['accessRightsPolicy'] rescue nil)
271
+ ].each do |data|
272
+ ie_data.merge! data if data
273
+ end
274
+ dossier_sheet = workbook.add_worksheet(id.gsub(/[\\\/*?]+/, '.'))
275
+ dossier_row = 0
276
+
277
+ ie[:content].each do |rep_name, rep|
278
+ next unless rep_name.is_a?(String)
279
+ @rep = rep
280
+ file_data_keys = Set.new %w(folder naam link mimetype puid formaat versie)
281
+ file_list = []
282
+
283
+ dossier_sheet.write_row(dossier_row, 0, [rep_name], rep_name_format)
284
+ %w(preservationType usageType).each do |key|
285
+ dossier_row += 1
286
+ dossier_sheet.write_row(
287
+ dossier_row, 0,
288
+ [
289
+ key.underscore.gsub('_', ' '),
290
+ rep[:amd][:tech]['generalRepCharacteristics'][key]
291
+ ]
292
+ )
293
+ end
294
+ dossier_row += 2
295
+
296
+ file_proc = lambda do |file|
297
+ @file = file
298
+ if file[:id]
299
+ tech = file[:amd][:tech]
300
+ # noinspection RubyStringKeysInHashInspection
301
+ file_data = {
302
+ 'folder' => (tech['generalFileCharacteristics']['fileOriginalPath'] rescue '').split('/')[1..-1].join('\\'),
303
+ 'naam' => (tech['generalFileCharacteristics']['fileOriginalName'] rescue nil),
304
+ 'link' => ("http://depot.lias.be/delivery/DeliveryManagerServlet?dps_pid=#{file[:id]}" rescue nil),
305
+ 'mimetype' => (tech['fileFormat']['mimeType'] rescue nil),
306
+ 'puid' => (tech['fileFormat']['formatRegistryId'] rescue nil),
307
+ 'formaat' => (tech['fileFormat']['formatDescription'] rescue nil),
308
+ 'versie' => (tech['fileFormat']['formatVersion'] rescue nil),
309
+ 'viruscheck' => (tech['fileVirusCheck']['status'] rescue nil),
310
+ 'file_type' => (tech['generalFileCharacteristics']['FileEntityType']),
311
+ 'groep' => file[:group],
312
+ }
313
+ data = tech['fileValidation']
314
+ if data
315
+ valid = (data['isValid'] == 'true') rescue nil
316
+ well_formed = (data['isWellFormed'] == 'true') rescue nil
317
+ file_data['validatie'] = if valid && well_formed
318
+ 'OK'
319
+ else
320
+ 'niet OK'
321
+ end
322
+ end
323
+ data = tech['significantProperties']
324
+ if data
325
+ file_data[data['significantPropertiesType']] = data['significantPropertiesValue']
326
+ end
327
+ data = file[:dmd]
328
+ if data
329
+ data.each { |key, value| file_data[key] = value }
330
+ end
331
+ file_list << file_data
332
+ file_data_keys.merge file_data.keys
333
+ else
334
+ file.each do |_, value|
335
+ next unless value.is_a? Hash
336
+ # noinspection RubyScope
337
+ file_proc.call(value)
338
+ end
339
+ end
340
+ end
341
+
342
+ rep.keys.each do |key|
343
+ file_proc.call(rep[key]) if key.is_a?(String)
344
+ end
345
+
346
+ table_start = dossier_row
347
+ dossier_sheet.write_row(dossier_row, 0, file_data_keys.to_a, file_header_format)
348
+ file_list.each do |file_info|
349
+ dossier_row += 1
350
+ file_data = []
351
+ file_data_keys.each { |key| file_data << file_info[key] }
352
+ dossier_sheet.write_row(dossier_row, 0, file_data)
353
+ end
354
+ table_end = dossier_row
355
+
356
+ dossier_sheet.add_table(
357
+ table_start, 0, table_end, file_data_keys.size - 1,
358
+ style: 'Table Style Medium 16', name: rep[:id],
359
+ columns: file_data_keys.map { |key| {header: key} }
360
+ )
361
+
362
+ dossier_row += 2
363
+ end
364
+ ie_data_keys.merge ie_data.keys
365
+ ie_list << ie_data
366
+ end
367
+ end
368
+
369
+ # write ie data to overview worksheet
370
+ overview.write_row(0, 0, ie_data_keys.to_a, ie_data_header_format)
371
+ overview_row = 1
372
+ ie_list.each do |ie_info|
373
+ ie_data = []
374
+ ie_data_keys.each { |key| ie_data << ie_info[key] }
375
+ overview.write_row(overview_row, 0, ie_data)
376
+ overview_row += 1
377
+ end
378
+
379
+ rescue Exception => e
380
+ puts e.message
381
+ puts e.backtrace
382
+ # close and save workbook
383
+ ensure
384
+ workbook.close
385
+ end
386
+
387
+ def file
388
+ @file
389
+ end
390
+
391
+ def ie
392
+ @ie
393
+ end
394
+
395
+ def rep
396
+ @rep
397
+ end
398
+
399
+ end
400
+
401
+ end
402
+ end
403
+ end
@@ -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