infopark_reactor_migrations 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/LICENSE +165 -0
- data/README +64 -0
- data/Rakefile +19 -0
- data/infopark_reactor_migrations.gemspec +27 -0
- data/lib/generators/cm/migration/USAGE +8 -0
- data/lib/generators/cm/migration/migration_generator.rb +15 -0
- data/lib/generators/cm/migration/templates/template.rb +7 -0
- data/lib/infopark_reactor_migrations.rb +29 -0
- data/lib/reactor/cm/attribute.rb +84 -0
- data/lib/reactor/cm/bridge.rb +49 -0
- data/lib/reactor/cm/editorial_group.rb +22 -0
- data/lib/reactor/cm/group.rb +270 -0
- data/lib/reactor/cm/language.rb +56 -0
- data/lib/reactor/cm/link.rb +132 -0
- data/lib/reactor/cm/live_group.rb +22 -0
- data/lib/reactor/cm/missing_credentials.rb +7 -0
- data/lib/reactor/cm/obj.rb +402 -0
- data/lib/reactor/cm/obj_class.rb +186 -0
- data/lib/reactor/cm/object_base.rb +164 -0
- data/lib/reactor/cm/user.rb +100 -0
- data/lib/reactor/cm/workflow.rb +40 -0
- data/lib/reactor/cm/xml_attribute.rb +35 -0
- data/lib/reactor/cm/xml_markup.rb +85 -0
- data/lib/reactor/cm/xml_request.rb +82 -0
- data/lib/reactor/cm/xml_request_error.rb +16 -0
- data/lib/reactor/cm/xml_response.rb +41 -0
- data/lib/reactor/configuration.rb +7 -0
- data/lib/reactor/migration.rb +82 -0
- data/lib/reactor/migrations/railtie.rb +10 -0
- data/lib/reactor/migrations/version.rb +5 -0
- data/lib/reactor/plans/common_attribute.rb +32 -0
- data/lib/reactor/plans/common_group.rb +44 -0
- data/lib/reactor/plans/common_obj_class.rb +69 -0
- data/lib/reactor/plans/create_attribute.rb +32 -0
- data/lib/reactor/plans/create_group.rb +34 -0
- data/lib/reactor/plans/create_obj.rb +48 -0
- data/lib/reactor/plans/create_obj_class.rb +28 -0
- data/lib/reactor/plans/delete_attribute.rb +23 -0
- data/lib/reactor/plans/delete_group.rb +28 -0
- data/lib/reactor/plans/delete_obj.rb +22 -0
- data/lib/reactor/plans/delete_obj_class.rb +22 -0
- data/lib/reactor/plans/prepared.rb +15 -0
- data/lib/reactor/plans/rename_group.rb +32 -0
- data/lib/reactor/plans/rename_obj_class.rb +24 -0
- data/lib/reactor/plans/update_attribute.rb +23 -0
- data/lib/reactor/plans/update_group.rb +30 -0
- data/lib/reactor/plans/update_obj.rb +30 -0
- data/lib/reactor/plans/update_obj_class.rb +26 -0
- data/lib/reactor/tools/migrator.rb +135 -0
- data/lib/reactor/tools/response_handler/base.rb +22 -0
- data/lib/reactor/tools/response_handler/string.rb +19 -0
- data/lib/reactor/tools/response_handler/xml_attribute.rb +52 -0
- data/lib/reactor/tools/smart_xml_logger.rb +69 -0
- data/lib/reactor/tools/sower.rb +89 -0
- data/lib/reactor/tools/uploader.rb +131 -0
- data/lib/reactor/tools/versioner.rb +120 -0
- data/lib/reactor/tools/xml_attributes.rb +70 -0
- data/lib/tasks/cm_migrate.rake +8 -0
- data/lib/tasks/cm_seeds.rake +41 -0
- metadata +193 -0
@@ -0,0 +1,402 @@
|
|
1
|
+
module Reactor
|
2
|
+
module Cm
|
3
|
+
class Obj
|
4
|
+
attr_reader :obj_id
|
5
|
+
OBJ_ATTRS = [:permalink, :objClass, :workflowName, :name, :suppressExport, :parent]
|
6
|
+
ATTR_LENGTH_CONSTRAINT = {:name => 250, :title => 250}
|
7
|
+
|
8
|
+
def self.create(name, parent, objClass)
|
9
|
+
obj = Obj.new(name)
|
10
|
+
obj.send(:create, parent, objClass)
|
11
|
+
obj
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.exists?(path_or_id)
|
15
|
+
obj = Obj.new
|
16
|
+
begin
|
17
|
+
obj.send(:load, path_or_id).ok?
|
18
|
+
rescue
|
19
|
+
return false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.get(path_or_id)
|
24
|
+
obj = Obj.new
|
25
|
+
obj.send(:load, path_or_id)
|
26
|
+
obj
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.delete_where(conditions)
|
30
|
+
request = XmlRequest.prepare do |xml|
|
31
|
+
|
32
|
+
xml.tag!('obj-where') do
|
33
|
+
conditions.each do |key, value|
|
34
|
+
xml.tag!(key, value)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
xml.tag!("obj-delete")
|
38
|
+
end
|
39
|
+
request.execute!
|
40
|
+
end
|
41
|
+
|
42
|
+
def upload(data_or_io, extension)
|
43
|
+
data = (data_or_io.kind_of?IO) ? data_or_io.read : data_or_io
|
44
|
+
base64_data = Base64.encode64(data)
|
45
|
+
|
46
|
+
set(:contentType, extension)
|
47
|
+
set(:blob, {base64_data=>{:encoding=>'base64'}})
|
48
|
+
end
|
49
|
+
|
50
|
+
def get(key)
|
51
|
+
request = XmlRequest.prepare do |xml|
|
52
|
+
xml.where_key_tag!(base_name, 'id', @obj_id)
|
53
|
+
xml.get_key_tag!(base_name, key)
|
54
|
+
end
|
55
|
+
response = request.execute!
|
56
|
+
result = response.xpath("//#{key}")
|
57
|
+
if result.children.map {|i| i.respond_to?(:name) && (i.name == "listitem") }.reduce(:&)
|
58
|
+
result.children.map {|i| i.text.to_s }
|
59
|
+
else
|
60
|
+
result = result.text unless result.is_a? Array
|
61
|
+
result
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def set(key, value, options={})
|
66
|
+
key = key.to_sym
|
67
|
+
value = value[0, ATTR_LENGTH_CONSTRAINT[key]] if ATTR_LENGTH_CONSTRAINT[key]
|
68
|
+
if OBJ_ATTRS.include?(key) then @obj_attrs[key] = value
|
69
|
+
else
|
70
|
+
@attrs[key] = value
|
71
|
+
end
|
72
|
+
@attr_options[key] = options
|
73
|
+
end
|
74
|
+
|
75
|
+
def permission_granted_to(user, permission)
|
76
|
+
request = XmlRequest.prepare do |xml|
|
77
|
+
xml.where_key_tag!(base_name, 'id', @obj_id)
|
78
|
+
xml.get_tag!(base_name) do
|
79
|
+
xml.tag!('permissionGrantedTo', :permission => permission, :user => user)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
response = request.execute!
|
83
|
+
response.xpath("//permissionGrantedTo/text()") == "1"
|
84
|
+
end
|
85
|
+
|
86
|
+
def permission_set(permission, groups)
|
87
|
+
request = XmlRequest.prepare do |xml|
|
88
|
+
xml.where_key_tag!(base_name, :id, @obj_id)
|
89
|
+
|
90
|
+
options = {
|
91
|
+
:permission => permission,
|
92
|
+
:type => :list,
|
93
|
+
}
|
94
|
+
|
95
|
+
xml.set_key_tag!(base_name, :permission, groups, options)
|
96
|
+
end
|
97
|
+
|
98
|
+
request.execute!
|
99
|
+
end
|
100
|
+
|
101
|
+
def permission_grant(permission, groups)
|
102
|
+
self.permission_command('GrantTo', permission, groups)
|
103
|
+
end
|
104
|
+
|
105
|
+
def permission_revoke(permission, groups)
|
106
|
+
self.permission_command('RevokeFrom', permission, groups)
|
107
|
+
end
|
108
|
+
|
109
|
+
def permission_clear(permission)
|
110
|
+
self.permission_set(permission, [])
|
111
|
+
end
|
112
|
+
|
113
|
+
def get_links(attr)
|
114
|
+
get_link_ids(attr).map {|id| Link.get(id)}
|
115
|
+
end
|
116
|
+
|
117
|
+
def set_links(attr, new_links_as_hashes)
|
118
|
+
get_links(attr).map(&:delete!)
|
119
|
+
new_links_as_hashes.each do |link_hash|
|
120
|
+
Link.create_inside(self, attr, link_hash[:destination_url], link_hash[:title])
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def set_link(attr, path)
|
125
|
+
old_links = get_links(attr)
|
126
|
+
if old_links.length == 1
|
127
|
+
old_link = old_links.first
|
128
|
+
old_link.dest_url = path
|
129
|
+
@links[attr] = [old_link]
|
130
|
+
else
|
131
|
+
@removed_links = old_links
|
132
|
+
@links[attr] = [Link.create_inside(self, attr, path)]
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def save!
|
137
|
+
edit! if not edited?
|
138
|
+
content = edited_content
|
139
|
+
@request = XmlRequest.prepare do |xml|
|
140
|
+
xml.where_key_tag!('content', 'id', content)
|
141
|
+
xml.tag!("content-set") do
|
142
|
+
@attrs.each do |key, value|
|
143
|
+
if (@attr_options[key] || {})[:cdata]
|
144
|
+
xml.tag!(key.to_s) do
|
145
|
+
xml.cdata!(value)
|
146
|
+
end
|
147
|
+
else
|
148
|
+
xml.value_tag!(key.to_s, value)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
response = @request.execute!
|
154
|
+
return response if !response.ok?
|
155
|
+
|
156
|
+
unless @obj_attrs.empty?
|
157
|
+
request = XmlRequest.prepare do |xml|
|
158
|
+
xml.where_key_tag!(base_name, 'id', @obj_id)
|
159
|
+
xml.set_tag!(base_name) do
|
160
|
+
@obj_attrs.each do |key, value|
|
161
|
+
xml.value_tag!(key, value)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
response = request.execute!
|
166
|
+
end
|
167
|
+
|
168
|
+
return response if !response.ok?
|
169
|
+
|
170
|
+
@removed_links.each do |link|
|
171
|
+
link.delete!
|
172
|
+
end
|
173
|
+
|
174
|
+
@links.each do |attr, links|
|
175
|
+
links.each do |link|
|
176
|
+
link.save!
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
|
182
|
+
def release!
|
183
|
+
simple_command("release")
|
184
|
+
end
|
185
|
+
|
186
|
+
def edit!
|
187
|
+
simple_command("edit")
|
188
|
+
end
|
189
|
+
|
190
|
+
def take!
|
191
|
+
simple_command("take")
|
192
|
+
end
|
193
|
+
|
194
|
+
def forward!
|
195
|
+
simple_command("forward")
|
196
|
+
end
|
197
|
+
|
198
|
+
def commit!
|
199
|
+
simple_command("commit")
|
200
|
+
end
|
201
|
+
|
202
|
+
def reject!
|
203
|
+
simple_command("reject")
|
204
|
+
end
|
205
|
+
|
206
|
+
def sign!
|
207
|
+
simple_command("sign")
|
208
|
+
end
|
209
|
+
|
210
|
+
def valid_actions
|
211
|
+
vcak = get('validControlActionKeys')
|
212
|
+
(vcak || []).map(&:to_s)
|
213
|
+
end
|
214
|
+
|
215
|
+
def copy(new_parent, recursive = false, new_name = nil)
|
216
|
+
request = XmlRequest.prepare do |xml|
|
217
|
+
xml.tag!('obj-where') do
|
218
|
+
xml.tag!("id", @obj_id)
|
219
|
+
end
|
220
|
+
xml.tag!("obj-copy") do
|
221
|
+
xml.tag!("parent", new_parent)
|
222
|
+
xml.tag!("name", new_name) if new_name
|
223
|
+
xml.tag!("recursive", "1") if recursive
|
224
|
+
end
|
225
|
+
end
|
226
|
+
response = request.execute!
|
227
|
+
response.xpath("//obj/id").text
|
228
|
+
end
|
229
|
+
|
230
|
+
def delete!
|
231
|
+
simple_command("delete")
|
232
|
+
end
|
233
|
+
|
234
|
+
def remove_active_contents!
|
235
|
+
simple_command("removeActiveContents")
|
236
|
+
end
|
237
|
+
|
238
|
+
def remove_archived_contents!
|
239
|
+
simple_command("removeArchivedContents")
|
240
|
+
end
|
241
|
+
|
242
|
+
def resolve_refs!
|
243
|
+
request = XmlRequest.prepare do |xml|
|
244
|
+
xml.tag!('content-where') do
|
245
|
+
xml.tag!('objectId', @obj_id)
|
246
|
+
xml.tag!('state', 'edited')
|
247
|
+
end
|
248
|
+
xml.tag!('content-resolveRefs')
|
249
|
+
end
|
250
|
+
response = request.execute!
|
251
|
+
end
|
252
|
+
|
253
|
+
def path
|
254
|
+
request = XmlRequest.prepare do |xml|
|
255
|
+
xml.where_key_tag!(base_name, 'id', @obj_id)
|
256
|
+
xml.get_key_tag!(base_name, 'path')
|
257
|
+
end
|
258
|
+
response = request.execute!
|
259
|
+
response.xpath("//obj/path").text
|
260
|
+
end
|
261
|
+
|
262
|
+
def edited?
|
263
|
+
request = XmlRequest.prepare do |xml|
|
264
|
+
xml.where_key_tag!(base_name, 'id', @obj_id)
|
265
|
+
xml.get_key_tag!(base_name, 'isEdited')
|
266
|
+
end
|
267
|
+
response = request.execute!
|
268
|
+
response.xpath("//isEdited").text == "1"
|
269
|
+
end
|
270
|
+
|
271
|
+
def reasons_for_incomplete_state
|
272
|
+
request = XmlRequest.prepare do |xml|
|
273
|
+
xml.tag!('content-where') do
|
274
|
+
xml.tag!('objectId', @obj_id)
|
275
|
+
xml.tag!('state', 'edited')
|
276
|
+
end
|
277
|
+
xml.get_key_tag!('content', 'reasonsForIncompleteState')
|
278
|
+
end
|
279
|
+
response = request.execute!
|
280
|
+
result = response.xpath('//reasonsForIncompleteState/*')
|
281
|
+
result.kind_of?(Array) ? result.map(&:text).map(&:to_s) : [result.to_s]
|
282
|
+
end
|
283
|
+
|
284
|
+
def editor
|
285
|
+
request = XmlRequest.prepare do |xml|
|
286
|
+
xml.tag!('content-where') do
|
287
|
+
xml.tag!('objectId', @obj_id)
|
288
|
+
xml.tag!('state', 'edited')
|
289
|
+
end
|
290
|
+
xml.get_key_tag!('content', 'editor')
|
291
|
+
end
|
292
|
+
response = request.execute!
|
293
|
+
response.xpath('//editor').text
|
294
|
+
end
|
295
|
+
|
296
|
+
def edited_content
|
297
|
+
request = XmlRequest.prepare do |xml|
|
298
|
+
xml.where_key_tag!(base_name, 'id', @obj_id)
|
299
|
+
xml.get_key_tag!(base_name, 'editedContent')
|
300
|
+
end
|
301
|
+
response = request.execute!
|
302
|
+
response.xpath("//editedContent").text
|
303
|
+
end
|
304
|
+
|
305
|
+
protected
|
306
|
+
def simple_command(cmd_name)
|
307
|
+
@request = XmlRequest.prepare do |xml|
|
308
|
+
xml.where_key_tag!(base_name, 'id', @obj_id)
|
309
|
+
xml.tag!("#{base_name}-#{cmd_name}")
|
310
|
+
end
|
311
|
+
response = @request.execute!
|
312
|
+
end
|
313
|
+
|
314
|
+
def base_name
|
315
|
+
'obj'
|
316
|
+
end
|
317
|
+
|
318
|
+
def get_content_attr_text(attr)
|
319
|
+
content = edited_content
|
320
|
+
request = XmlRequest.prepare do |xml|
|
321
|
+
xml.where_key_tag!('content', 'id', content)
|
322
|
+
xml.get_tag!('content') do
|
323
|
+
xml.tag!(attr.to_s)
|
324
|
+
end
|
325
|
+
end
|
326
|
+
response = request.execute!
|
327
|
+
txt = response.xpath("//#{attr}/text()")
|
328
|
+
txt.class.unnormalize(txt.to_s)
|
329
|
+
end
|
330
|
+
|
331
|
+
def get_link_ids(attr)
|
332
|
+
content = edited_content
|
333
|
+
request = XmlRequest.prepare do |xml|
|
334
|
+
xml.where_key_tag!('content', 'id', content)
|
335
|
+
xml.get_key_tag!('content', attr.to_s)
|
336
|
+
end
|
337
|
+
response = request.execute!
|
338
|
+
result = response.xpath("//listitem/text()")
|
339
|
+
result.kind_of?(Array) ? result : [result]
|
340
|
+
rescue XmlRequestError
|
341
|
+
[]
|
342
|
+
end
|
343
|
+
|
344
|
+
def self.extract_id(response)
|
345
|
+
response.xpath("//obj/id").text
|
346
|
+
end
|
347
|
+
|
348
|
+
def initialize(name=nil)
|
349
|
+
@name = name
|
350
|
+
@attrs = {}
|
351
|
+
@obj_attrs = {}
|
352
|
+
@links = {}
|
353
|
+
@removed_links = []
|
354
|
+
@attr_options = {}
|
355
|
+
end
|
356
|
+
|
357
|
+
def create(parent, objClass)
|
358
|
+
@request = XmlRequest.prepare do |xml|
|
359
|
+
xml.where_key_tag!(base_name, 'path', parent)
|
360
|
+
xml.create_tag!(base_name) do
|
361
|
+
xml.tag!('objClass') do
|
362
|
+
xml.text!(objClass)
|
363
|
+
end
|
364
|
+
xml.tag!('name') do
|
365
|
+
xml.text!(@name)
|
366
|
+
end
|
367
|
+
end
|
368
|
+
end
|
369
|
+
response = @request.execute!
|
370
|
+
@obj_id = self.class.extract_id(response)
|
371
|
+
response
|
372
|
+
end
|
373
|
+
|
374
|
+
def load(path_or_id)
|
375
|
+
key = (/^\// =~ path_or_id.to_s) ? 'path' : 'id'
|
376
|
+
value = path_or_id
|
377
|
+
|
378
|
+
@request = XmlRequest.prepare do |xml|
|
379
|
+
xml.where_key_tag!(base_name, key.to_s, value.to_s)
|
380
|
+
xml.get_key_tag!(base_name, 'id')
|
381
|
+
end
|
382
|
+
response = @request.execute!
|
383
|
+
@obj_id = self.class.extract_id(response)
|
384
|
+
response
|
385
|
+
end
|
386
|
+
|
387
|
+
def permission_command(type, permission, groups)
|
388
|
+
request = XmlRequest.prepare do |xml|
|
389
|
+
xml.where_key_tag!(base_name, 'id', @obj_id)
|
390
|
+
|
391
|
+
xml.tag!("#{base_name}-permission#{type}", :permission => permission) do
|
392
|
+
groups.each do |name|
|
393
|
+
xml.tag!(:group, name)
|
394
|
+
end
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
398
|
+
request.execute!
|
399
|
+
end
|
400
|
+
end
|
401
|
+
end
|
402
|
+
end
|
@@ -0,0 +1,186 @@
|
|
1
|
+
require 'reactor/cm/xml_request'
|
2
|
+
require 'reactor/cm/xml_response'
|
3
|
+
require 'reactor/cm/xml_request_error'
|
4
|
+
|
5
|
+
module Reactor
|
6
|
+
module Cm
|
7
|
+
class ObjClass
|
8
|
+
def self.exists?(name)
|
9
|
+
klass = ObjClass.new
|
10
|
+
begin
|
11
|
+
return klass.send(:get, name).ok?
|
12
|
+
rescue
|
13
|
+
return false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.create(name, type)
|
18
|
+
klass = ObjClass.new
|
19
|
+
klass.send(:create,name, type)
|
20
|
+
klass
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.get(name)
|
24
|
+
klass = ObjClass.new
|
25
|
+
klass.send(:get, name)
|
26
|
+
klass
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.rename(current_name, new_name)
|
30
|
+
request = XmlRequest.prepare do |xml|
|
31
|
+
xml.tag!('objClass-where') do
|
32
|
+
xml.tag!('name', current_name)
|
33
|
+
end
|
34
|
+
xml.tag!('objClass-set') do
|
35
|
+
xml.tag!('name', new_name)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
request.execute!
|
39
|
+
end
|
40
|
+
|
41
|
+
def set(key, value, options={})
|
42
|
+
@params_options[key.to_sym] = (!options.nil? && !options.empty? && options) || {}
|
43
|
+
@params[key.to_sym] = value
|
44
|
+
end
|
45
|
+
|
46
|
+
def preset(key, value)
|
47
|
+
@preset[key] = value
|
48
|
+
end
|
49
|
+
|
50
|
+
def preset_attributes
|
51
|
+
request = XmlRequest.prepare do |xml|
|
52
|
+
xml.where_key_tag!(base_name, 'name', @name)
|
53
|
+
xml.get_key_tag!(base_name, 'presetAttributes')
|
54
|
+
end
|
55
|
+
response = request.execute!
|
56
|
+
result = response.xpath('//dictitem')
|
57
|
+
result = [result] unless result.kind_of?(Array)
|
58
|
+
result.map do |dictitem|
|
59
|
+
key = dictitem.children.detect {|c| c.name == 'key'}.text
|
60
|
+
value = dictitem.children.detect {|c| c.name == 'value'}.text
|
61
|
+
{key => value}
|
62
|
+
end.inject({}, &:merge)
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
def save!
|
67
|
+
request = XmlRequest.prepare do |xml|
|
68
|
+
xml.where_key_tag!(base_name, 'name', @name)
|
69
|
+
xml.set_tag!(base_name) do
|
70
|
+
@params.each do |key, value|
|
71
|
+
if @params_options[key][:cdata]
|
72
|
+
xml.tag!(key.to_s) do
|
73
|
+
xml.cdata!(value)
|
74
|
+
end
|
75
|
+
else
|
76
|
+
xml.value_tag!(key.to_s, value)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
unless @preset.empty?
|
80
|
+
all_preset = (preset_attributes.merge(@preset))
|
81
|
+
xml.tag!('presetAttributes') do
|
82
|
+
@preset.each do |key, value|
|
83
|
+
xml.tag!('dictitem') do
|
84
|
+
xml.tag!('key') do
|
85
|
+
xml.text!(key.to_s)
|
86
|
+
end
|
87
|
+
xml.tag!('value') do
|
88
|
+
xml.text!(value.to_s)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
response = request.execute!
|
97
|
+
end
|
98
|
+
|
99
|
+
def has_attribute?(attr_name)
|
100
|
+
attributes.include? attr_name
|
101
|
+
end
|
102
|
+
|
103
|
+
def attributes
|
104
|
+
__attributes_get('attributes')
|
105
|
+
end
|
106
|
+
|
107
|
+
def attributes=(attr_arr)
|
108
|
+
__attributes_set('attributes', attr_arr)
|
109
|
+
end
|
110
|
+
|
111
|
+
def mandatory_attributes
|
112
|
+
__attributes_get('mandatoryAttributes')
|
113
|
+
end
|
114
|
+
|
115
|
+
def mandatory_attributes=(attr_arr)
|
116
|
+
__attributes_set('mandatoryAttributes', attr_arr)
|
117
|
+
end
|
118
|
+
|
119
|
+
def delete!
|
120
|
+
request = XmlRequest.prepare do |xml|
|
121
|
+
xml.where_key_tag!(base_name, 'name', @name)
|
122
|
+
xml.tag!("#{base_name}-delete")
|
123
|
+
end
|
124
|
+
response = request.execute!
|
125
|
+
end
|
126
|
+
|
127
|
+
protected
|
128
|
+
def base_name
|
129
|
+
'objClass'
|
130
|
+
end
|
131
|
+
|
132
|
+
def initialize(name=nil)
|
133
|
+
@name = name
|
134
|
+
@params = {}
|
135
|
+
@params_options = {}
|
136
|
+
@preset = {}
|
137
|
+
end
|
138
|
+
|
139
|
+
def get(name)
|
140
|
+
request = XmlRequest.prepare do |xml|
|
141
|
+
xml.where_key_tag!(base_name, 'name', name)
|
142
|
+
xml.get_key_tag!(base_name, 'name')
|
143
|
+
end
|
144
|
+
response = request.execute!
|
145
|
+
@name = name
|
146
|
+
response
|
147
|
+
end
|
148
|
+
|
149
|
+
def create(name, type)
|
150
|
+
request = XmlRequest.prepare do |xml|
|
151
|
+
xml.create_tag!(base_name) do |xml|
|
152
|
+
xml.tag!('name') do
|
153
|
+
xml.text!(name)
|
154
|
+
end
|
155
|
+
xml.tag!('objType') do
|
156
|
+
xml.text!(type)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
response = request.execute!
|
161
|
+
@name = name
|
162
|
+
response
|
163
|
+
end
|
164
|
+
|
165
|
+
private
|
166
|
+
def __attributes_get(field)
|
167
|
+
request = XmlRequest.prepare do |xml|
|
168
|
+
xml.where_key_tag!(base_name, 'name', @name)
|
169
|
+
xml.get_key_tag!(base_name, field)
|
170
|
+
end
|
171
|
+
response = request.execute!
|
172
|
+
items = response.xpath("//listitem/text()")
|
173
|
+
return [items.to_s] unless items.kind_of?(Array)
|
174
|
+
items.map(&:to_s)
|
175
|
+
end
|
176
|
+
|
177
|
+
def __attributes_set(field, attr_arr)
|
178
|
+
request = XmlRequest.prepare do |xml|
|
179
|
+
xml.where_key_tag!(base_name, 'name', @name)
|
180
|
+
xml.set_key_tag!(base_name, field, attr_arr)
|
181
|
+
end
|
182
|
+
response = request.execute!
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|