libis-services 0.0.2
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.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +36 -0
- data/Rakefile +6 -0
- data/lib/libis-services.rb +1 -0
- data/lib/libis/services.rb +21 -0
- data/lib/libis/services/aleph/search.rb +157 -0
- data/lib/libis/services/collective_access.rb +1 -0
- data/lib/libis/services/collective_access/cataloguing.rb +48 -0
- data/lib/libis/services/collective_access/connector.rb +151 -0
- data/lib/libis/services/collective_access/item_info.rb +36 -0
- data/lib/libis/services/collective_access/search.rb +26 -0
- data/lib/libis/services/collective_access/service.rb +80 -0
- data/lib/libis/services/digitool/digital_entity_manager.rb +223 -0
- data/lib/libis/services/digitool/digitool_connector.rb +46 -0
- data/lib/libis/services/digitool/meta_data_manager.rb +193 -0
- data/lib/libis/services/extend/http_fetch.rb +63 -0
- data/lib/libis/services/generic_search.rb +38 -0
- data/lib/libis/services/http_error.rb +21 -0
- data/lib/libis/services/oracle_client.rb +47 -0
- data/lib/libis/services/primo.rb +2 -0
- data/lib/libis/services/primo/limo.rb +33 -0
- data/lib/libis/services/primo/search.rb +46 -0
- data/lib/libis/services/rest_client.rb +66 -0
- data/lib/libis/services/rosetta.rb +1 -0
- data/lib/libis/services/rosetta/client.rb +107 -0
- data/lib/libis/services/rosetta/collection_handler.rb +45 -0
- data/lib/libis/services/rosetta/collection_info.rb +35 -0
- data/lib/libis/services/rosetta/deposit_activity.rb +48 -0
- data/lib/libis/services/rosetta/deposit_handler.rb +187 -0
- data/lib/libis/services/rosetta/ie.rb +19 -0
- data/lib/libis/services/rosetta/ie_handler.rb +29 -0
- data/lib/libis/services/rosetta/pds_handler.rb +60 -0
- data/lib/libis/services/rosetta/producer.rb +71 -0
- data/lib/libis/services/rosetta/producer_handler.rb +125 -0
- data/lib/libis/services/rosetta/service.rb +399 -0
- data/lib/libis/services/rosetta/sip.rb +26 -0
- data/lib/libis/services/rosetta/sip_handler.rb +30 -0
- data/lib/libis/services/rosetta/user.rb +70 -0
- data/lib/libis/services/rosetta/user_manager.rb +28 -0
- data/lib/libis/services/scope/search.rb +46 -0
- data/lib/libis/services/search_factory.rb +40 -0
- data/lib/libis/services/sharepoint/connector.rb +236 -0
- data/lib/libis/services/sharepoint/search.rb +19 -0
- data/lib/libis/services/soap_client.rb +57 -0
- data/lib/libis/services/soap_error.rb +22 -0
- data/lib/libis/services/version.rb +5 -0
- data/libis-services.gemspec +38 -0
- data/spec/primo_limo_spec.rb +394 -0
- data/spec/primo_search_spec.rb +39 -0
- data/spec/rosetta_collection_spec.rb +206 -0
- data/spec/rosetta_deposit_spec.rb +82 -0
- data/spec/rosetta_ie_spec.rb +345 -0
- data/spec/rosetta_pds_spec.rb +79 -0
- data/spec/rosetta_producer_spec.rb +270 -0
- data/spec/rosetta_sip_spec.rb +39 -0
- data/spec/spec_helper.rb +12 -0
- metadata +307 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require_relative 'connector'
|
4
|
+
|
5
|
+
module Libis
|
6
|
+
module Services
|
7
|
+
module CollectiveAccess
|
8
|
+
|
9
|
+
class ItemInfo < Connector
|
10
|
+
|
11
|
+
def initialize(host = nil)
|
12
|
+
super 'ItemInfo', host
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_attributes(item, type = nil)
|
16
|
+
type ||= 'ca_objects'
|
17
|
+
request :getAttributes, type: type, item_id: item.to_s
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_attribute(item, attribute, type = nil)
|
21
|
+
type ||= 'ca_objects'
|
22
|
+
request :getAttributesByElement, type: type, item_id: item.to_s, attribute_code_or_id: attribute.to_s
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_items(item_list, bundle, type = nil)
|
26
|
+
type ||= 'ca_objects'
|
27
|
+
r1, a1 = soap_encode item_list
|
28
|
+
r2, a2 = soap_encode bundle
|
29
|
+
request :get, type: type, item_ids: r1, bundles: r2, :attributes! => {item_ids: a1, bundles: a2}
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'libis/services/generic_search'
|
4
|
+
|
5
|
+
require_relative 'connector'
|
6
|
+
|
7
|
+
module Libis
|
8
|
+
module Services
|
9
|
+
module CollectiveAccess
|
10
|
+
|
11
|
+
class Search < Connector
|
12
|
+
include ::Libis::Services::GenericSearch
|
13
|
+
|
14
|
+
def initialize(host = nil)
|
15
|
+
super 'Search', host
|
16
|
+
end
|
17
|
+
|
18
|
+
def query(query, options = {})
|
19
|
+
request :querySoap, type: (options[:index] || 'ca_objects'), query: query
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require_relative 'search'
|
4
|
+
require_relative 'item_info'
|
5
|
+
require_relative 'cataloguing'
|
6
|
+
|
7
|
+
module Libis
|
8
|
+
module Services
|
9
|
+
module CollectiveAccess
|
10
|
+
|
11
|
+
class Service
|
12
|
+
|
13
|
+
attr_reader :search, :info, :cata
|
14
|
+
|
15
|
+
def initialize(host = nil)
|
16
|
+
@search = ::Libis::Services::CollectiveAccess::Search.new host
|
17
|
+
@info = ::Libis::Services::CollectiveAccess::ItemInfo.new host
|
18
|
+
@cata = ::Libis::Services::CollectiveAccess::Cataloguing.new host
|
19
|
+
end
|
20
|
+
|
21
|
+
def authenticate(name = nil, password = nil)
|
22
|
+
result = @search.authenticate name, password
|
23
|
+
result &&= @info.authenticate name, password
|
24
|
+
result && @cata.authenticate(name, password)
|
25
|
+
end
|
26
|
+
|
27
|
+
def deauthenticate
|
28
|
+
@search.deauthenticate
|
29
|
+
@info.deauthenticate
|
30
|
+
@cata.deauthenticate
|
31
|
+
end
|
32
|
+
|
33
|
+
def add_object(label)
|
34
|
+
@cata.add_item idno: label, type_id: 21
|
35
|
+
end
|
36
|
+
|
37
|
+
def search_object(attributes = {})
|
38
|
+
query = attributes.delete :query || ''
|
39
|
+
query = attributes.inject(query) { |q, (k, v)|
|
40
|
+
q << ' AND ' unless q.empty?
|
41
|
+
q << k << ':' if k
|
42
|
+
v = "\"#{v}\"" if v.is_a?(String) and !v.include? '"'
|
43
|
+
q << v
|
44
|
+
}
|
45
|
+
result = @search.query query
|
46
|
+
return nil unless result && result.is_a?(Hash) && !result.empty?
|
47
|
+
result.first[0]
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_object(label)
|
51
|
+
search_object query: "\"#{label}\""
|
52
|
+
end
|
53
|
+
|
54
|
+
def delete_object(object)
|
55
|
+
@cata.remove object
|
56
|
+
end
|
57
|
+
|
58
|
+
def add_attribute(object, attribute, value)
|
59
|
+
@cata.add_attribute object, attribute.to_s, {attribute.to_sym => value}
|
60
|
+
end
|
61
|
+
|
62
|
+
def get_attribute(object, attribute)
|
63
|
+
result = @info.get_attribute object, attribute
|
64
|
+
result = [result] unless result.is_a? Array
|
65
|
+
result
|
66
|
+
end
|
67
|
+
|
68
|
+
def delete_attribute(_, _) #object, attribute)
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
def delete_attributes(object)
|
73
|
+
@cata.remove_attributes object
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -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!('&','&')
|
27
|
+
# dc_string.gsub!('<', '<')
|
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
|