usd 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/bin/rusdc +63 -22
  3. data/change_log.md +1 -1
  4. data/lib/usd.rb +7 -2
  5. data/usd.gemspec +1 -1
  6. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 20e10b3d05b2877410dd4f039533d7e9c8281fe9b5b96bfb8a77b29992327dcc
4
- data.tar.gz: a12edecd3c4078d5d9a0f107693d4af9b5d90496c53e8128016d68ca0bf6c7f2
3
+ metadata.gz: d3fcd67e1d03c8438152bd6a247c644d72b4d7300ae8e434d5e0920772df6473
4
+ data.tar.gz: 49289a822d2906027417ac0d56d621a1cd1b53766ff651b5069858a8bb221d6e
5
5
  SHA512:
6
- metadata.gz: 07b9914696ee9028670074977518c4486ce5febd6edb6e2855d1afb933527a3a54af7f1668dd47631d2ab4349c8c6eb672a5d9af7a1cbdcdbc3d4fb7ec99c1e9
7
- data.tar.gz: 3ea37ce6ec628daf61b61ddd86e02ca1791ae86ded68c0aea437086e9bb17b39c4be399d2fd2b6cf8b750e52ec495bfcda07a573d768138816ef8cfd99b31ff6
6
+ metadata.gz: 4e4f7fde898d1b6477b9c08e96811b738d45e40fffffd16f3c0d474c1629d3e2a0ba4079b453623917a1d111f11b6989e83378b63e728c334936c4ecce271f5b
7
+ data.tar.gz: b517f049992b629a745e23c0af441814a7f45486a9a0617b6a69ae319cd6c68df9cf0561ac1033d1d4bc63e045d281836067f40e24fc6ca6c2985d9f401967e0
data/bin/rusdc CHANGED
@@ -280,36 +280,77 @@ class Rusdc < Thor
280
280
  puts loadcon.update({:type => "json", :data => STDIN.read})
281
281
  end
282
282
 
283
- desc "update_attr <obj> <common_name> <key> <value>", "updates a direct (not referenced) attribute of one object."
283
+ desc "update_attr <obj> <common_name|wc> <key> <value>", "updates a direct (not referenced) attribute of one or more objects."
284
284
  option :plain_text, :type => :boolean, :default => false
285
285
  def update_attr(obj, cn, k, v)
286
286
  if k =~ /(date|last_mod|warranty_start|warranty_end|time_stamp)$/
287
287
  v=Time.parse(v).to_i
288
288
  end
289
- if options[:plain_text]
290
- data={
291
- obj => {
292
- "@COMMON_NAME" => cn,
293
- k => v
294
- }
295
- }
296
- json = JSON.pretty_generate(data)
289
+ if cn =~ /([<>=]| like )/
290
+ obj_arr=loadcon.search(obj,{'fields' => "@id","wc"=>"#{cn} and delete_flag.sym = 'Active'"})
291
+ obj_arr.each do |inner_obj|
292
+ inner_id=inner_obj["@id"]
293
+ template = ERB.new <<-EOF
294
+ {
295
+ "<%= obj %>": {
296
+ "@id": "<%= id %>",
297
+ "<%= k %>": "<%= v %>"
298
+ }
299
+ }
300
+ EOF
301
+ json = template.result_with_hash({
302
+ :obj => obj,
303
+ :id => inner_id,
304
+ :k => k,
305
+ :v => v
306
+ })
307
+ puts loadcon.update({:type => "json", :data => json})
308
+ end
297
309
  else
298
- template = ERB.new <<-EOF
299
- {
300
- "<%= obj %>": {
301
- "@COMMON_NAME": "<%= cn %>",
302
- "<%= k %>": "<%= v %>"
310
+ if options[:plain_text]
311
+ data={
312
+ obj => {
313
+ "@COMMON_NAME" => cn,
314
+ k => v
303
315
  }
304
316
  }
305
- EOF
306
- json = template.result_with_hash({
317
+ json = JSON.pretty_generate(data)
318
+ else
319
+ template = ERB.new <<-EOF
320
+ {
321
+ "<%= obj %>": {
322
+ "@COMMON_NAME": "<%= cn %>",
323
+ "<%= k %>": "<%= v %>"
324
+ }
325
+ }
326
+ EOF
327
+ json = template.result_with_hash({
328
+ :obj => obj,
329
+ :cn => cn,
330
+ :k => k,
331
+ :v => v
332
+ })
333
+ end
334
+ puts loadcon.update({:type => "json", :data => json})
335
+ end
336
+ end
337
+
338
+ desc "update_attr_by_id <obj> <id> <key> <value>", "updates a plain attribute of one object by id, does not work"
339
+ def update_attr_by_id(obj, id, k, v)
340
+ template = ERB.new <<-EOF
341
+ {
342
+ "<%= obj %>": {
343
+ "@id": "<%= id %>",
344
+ "<%= k %>": "<%= v %>"
345
+ }
346
+ }
347
+ EOF
348
+ json = template.result_with_hash({
307
349
  :obj => obj,
308
- :cn => cn,
350
+ :id => id,
309
351
  :k => k,
310
352
  :v => v
311
353
  })
312
- end
313
354
  puts loadcon.update({:type => "json", :data => json})
314
355
  end
315
356
 
@@ -334,12 +375,12 @@ class Rusdc < Thor
334
375
  puts loadcon.update({:type => "json", :data => json})
335
376
  end
336
377
 
337
- desc "update_ref_attr_by_id <obj> <common_name> <key> <id>", "updates a referenced attribute of one object by id"
338
- def update_ref_attr_by_id(obj, cn, k, v)
378
+ desc "update_ref_attr_by_id <obj> <id> <key> <value>", "updates a referenced attribute of one object by id"
379
+ def update_ref_attr_by_id(obj, id, k, v)
339
380
  template = ERB.new <<-EOF
340
381
  {
341
382
  "<%= obj %>": {
342
- "@COMMON_NAME": "<%= cn %>",
383
+ "@id": "<%= id %>",
343
384
  "<%= k %>": {
344
385
  "@id": "<%= v %>"
345
386
  }
@@ -348,7 +389,7 @@ class Rusdc < Thor
348
389
  EOF
349
390
  json = template.result_with_hash({
350
391
  :obj => obj,
351
- :cn => cn,
392
+ :id => id,
352
393
  :k => k,
353
394
  :v => v
354
395
  })
@@ -1,6 +1,6 @@
1
1
  # changelog
2
2
 
3
- ## 0.2.0
3
+ ## 0.2.1
4
4
 
5
5
  - function `update_attr` has a new option for putting plain text with linebreaks in it.
6
6
 
data/lib/usd.rb CHANGED
@@ -147,8 +147,13 @@ class Usd
147
147
  end
148
148
  puts "update - data: #{JSON.pretty_generate(data)}" if @debug
149
149
  object = data.keys[0]
150
- cn = data[object]["@COMMON_NAME"]
151
- request("/caisd-rest/#{object}/COMMON_NAME-#{cn}",{:method => "put", :json => data.to_json, :header => header({'X-Obj-Attrs' => 'COMMON_NAME'})})
150
+ if data[object].has_key?("@id")
151
+ request("/caisd-rest/#{object}/#{data[object]["@id"]}",{:method => "put", :json => data.to_json, :header => header({'X-Obj-Attrs' => 'COMMON_NAME'})})
152
+ elsif data[object].has_key?("@COMMON_NAME")
153
+ request("/caisd-rest/#{object}/COMMON_NAME-#{data[object]["@COMMON_NAME"]}",{:method => "put", :json => data.to_json, :header => header({'X-Obj-Attrs' => 'COMMON_NAME'})})
154
+ else
155
+ puts "specify @COMMON_NAME or @id at least."
156
+ end
152
157
  end
153
158
 
154
159
  def set_url_parm(params_hash,attribute_name,default)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'usd'
3
- spec.version = '0.2.1'
3
+ spec.version = '0.2.2'
4
4
  spec.date = '2019-11-26'
5
5
  spec.summary = "SDM REST-API-Calls"
6
6
  spec.description = "a Ruby class and a commandlinetool for SDM REST-API-Calls"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oliver Gaida