usd 1.2 → 1.3.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 278dc411942f77e45434ee0463e50b748af2f65f373923107b979d4c41cf8064
4
- data.tar.gz: '0265695f32cf5e377cf94d0e49c1370923d278cd625b557bc188bd0bd1bb6f0e'
3
+ metadata.gz: e2dc7c020bc56752e81b0ca22201b6661e17a1fcf54ffb37295ce19ad779fd7d
4
+ data.tar.gz: ef77af20f3e5a2c1b6b71c2f8a78cad5f38da174908c33da9ef6a41c8fcb71be
5
5
  SHA512:
6
- metadata.gz: 8ade7a831bc17847218142b30ad9a0d30b57d2b214b021c42befc4775271a376ec4d2a600ea0272595da3b1f018fc5a02b1a5f51792995142e7a3936b0ed624e
7
- data.tar.gz: 650d000528d4af5d2132e7737dca6aa2fbcfd9e0bb74d85b981753727ef2f9feb80c5d82fcae33c3456d7a0818053b947ddfe066bb7c59b022496850d65f38c4
6
+ metadata.gz: 0edea409a25f20dac2a91f5ecdacfaf9fbf5b954d7d30801a5c12cf23080789c3f616f2d08947632cf90efdd55cb1ed1fc1bf46870921789e759782739d51344
7
+ data.tar.gz: 972f687caeea7d9a6b71a1704018ff67cc2da94e81849fbc0aaca93f27eb1b43c7f9b3a44a4917c095e8344f48caa277a76faf7a79bb04262539338e97c9cc66
data/README.md CHANGED
@@ -3,6 +3,8 @@
3
3
 
4
4
  There is a ruby class and a commandline tool rusdc.
5
5
 
6
+ [![asciicast](https://asciinema.org/a/7zw3RLpikFluqX9XJMxCpMEmS.svg)](https://asciinema.org/a/7zw3RLpikFluqX9XJMxCpMEmS)
7
+
6
8
  # installation
7
9
 
8
10
  just install the gem:
@@ -30,31 +32,36 @@ yum install ruby-devel
30
32
 
31
33
  see [https://github.com/ogaida/usd/wiki/bash-completion](https://github.com/ogaida/usd/wiki/bash-completion)
32
34
 
33
- # external tools
35
+ # external tools / requirements
34
36
 
35
37
  If you use the `rusdc find` command with `--format mlr` option then you need `mlr`.
36
38
 
37
39
  - [mlr - Miller](http://johnkerl.org/miller/doc/index.html) - a great tool for data-transforming to and from json, csv and many more
38
40
 
39
- Place the `mlr`-binary in a path, which is in your PATH-Environment. Download-Url for mlr-releases: [https://github.com/johnkerl/miller/releases](https://github.com/johnkerl/miller/releases)
41
+ Place the `mlr`-binary in a path, which is in your PATH-Environment. Download-Url for mlr-releases: [https://github.com/johnkerl/miller/releases](https://github.com/johnkerl/miller/releases).
40
42
 
41
43
  # functions from the commandline-tool `rusdc`
42
44
 
43
45
  ```
46
+ rusdc chg_add_attachment <co> <file> # attach the file to co
44
47
  rusdc chg_add_nr <co> <ci> # add a CI to a changeorder
45
48
  rusdc chg_list_nr <co> # list all CIs of one changeorder
46
49
  rusdc create # pipe json-data to create object
47
50
  rusdc field_names <object-type> [wc] # list all fields of an object including its format
48
51
  rusdc find <object-type> [where-clause] [fields, comma separated] [options] # finds each object which meets the wc-condition
49
52
  rusdc get <object-type> <common_name|id> # shows one object by name or id
50
- rusdc get_all_attachments_of_co <co_name> # get all attachments of a changeorder and save all th...
51
- rusdc get_attachment_of_ci <ci_name> <filename> # download an attachment of a CI and print it out on s...
52
- rusdc get_attachment_of_co <co_name> <filename> # download an attachment of a changeorder and print it...
53
+ rusdc get_all_attachments_of_co <co_name> # get all attachments of a changeorder and save all these to current folder
54
+ rusdc get_attachment_of_ci <ci_name> <filename> # download an attachment of a CI and print it out on stdout
55
+ rusdc get_attachment_of_co <co_name> <filename> # download an attachment of a changeorder and print it out on stdout
56
+ rusdc get_attachment_of_in <incident> <filename> # download an attachment of an Incident and print it out on stdout
53
57
  rusdc help [COMMAND] # Describe available commands or one specific command
54
58
  rusdc in_add_2_chg <changeorder> <incident> # add incident to changeorder
59
+ rusdc in_add_attachment <in> <file> # attach the file to incident
55
60
  rusdc in_list_child_ins <in> # list all child-incidents of one incident
56
61
  rusdc list_attachments_of_ci <ci_name> # list all attachments of a CI
57
62
  rusdc list_attachments_of_co <co_name> # list all attachments of a changeorder
63
+ rusdc list_attachments_of_in <in> # list all attachments of an Incident
64
+ rusdc nr_add_attachment <nr> <file> # attach the file to nr
58
65
  rusdc nr_add_child <nr-name> <child-name> # add one child CI to another CI
59
66
  rusdc nr_add_org <nr> <org> # add an Organisation to a ConfigurationItem
60
67
  rusdc nr_changes <nr> [inactive-too] # list all open changeorders of one CI
@@ -62,10 +69,11 @@ rusdc nr_childs <ci-name> # l
62
69
  rusdc nr_incidents <nr> [inactive-too] # lists all incident of a specific CI
63
70
  rusdc nr_parents <ci-name> # lists all parent CIs of a specific CI
64
71
  rusdc update # pipe json-data to update object
65
- rusdc update_attr <obj> <common_name|wc> <key> <value> # updates a direct (not referenced) attribute of one o...
66
- rusdc update_attr_by_id <obj> <id> <key> <value> # updates a plain attribute of one object by id, does ...
67
- rusdc update_ref_attr <obj> <common_name> <key> <value> # updates a referenced attribute of one object.
68
- rusdc update_ref_attr_by_id <obj> <id> <key> <value_id> # updates a referenced attribute of one object_id by v...
72
+ rusdc update_attr <obj> <common_name|wc> <key> <value> # updates a direct (not referenced) attribute of one or more objects.
73
+ rusdc update_attr_by_id <obj> <id> <key> <value> # updates a plain attribute of one object by id, does not work
74
+ rusdc update_ref_attr <obj> <common_name> <key> <value> [ref_obj=nr] # updates a referenced attribute of one object.
75
+ rusdc update_ref_attr_by_id <obj> <id> <key> <value_id> # updates a referenced attribute of one object_id by value-id
76
+ rusdc vcard_via_email <email> # creates a vcard from the given email-address and saves it in the /tmp directory.
69
77
  ```
70
78
 
71
79
  # environment-variables
data/bin/rusdc CHANGED
@@ -7,6 +7,31 @@ require "usd"
7
7
 
8
8
  class Rusdc < Thor
9
9
 
10
+ desc "chg_add_attachment <co> <file>", "attach the file to co"
11
+ def chg_add_attachment(co, file)
12
+ response = loadcon.upload_attachment(file)
13
+ puts response
14
+ data = JSON.parse(response)
15
+ template = ERB.new <<-EOF
16
+ {
17
+ "lrel_attachments_changes": {
18
+ "attmnt": {
19
+ "@id": "<%= id %>"
20
+ },
21
+ "chg": {
22
+ "@COMMON_NAME": "<%= co %>"
23
+ }
24
+ }
25
+ }
26
+ EOF
27
+ json = template.result_with_hash({
28
+ :id => data["attmnt"]["@id"],
29
+ :co => co
30
+ })
31
+ #puts "create relation to chg with json: #{json}"
32
+ puts loadcon.create({:type => "json", :data => json})
33
+ end
34
+
10
35
  desc "chg_add_nr <co> <ci>", "add a CI to a changeorder"
11
36
  def chg_add_nr(co, ci)
12
37
  template = ERB.new <<-EOF
@@ -194,11 +219,10 @@ class Rusdc < Thor
194
219
  end
195
220
  end
196
221
 
197
- desc "get_attachment_of_co <co_name> <filename>", "download an attachment of a changeorder and print it out on stdout"
198
- def get_attachment_of_co(coname, filename)
199
- chg_id=loadcon.request("/caisd-rest/chg/COMMON_NAME-#{coname}")["chg"]["@id"]
200
- att_nr = loadcon.search("lrel_attachments_changes",{'fields' => "attmnt","wc" => "chg = #{chg_id}"})
201
- att_nr.each do |att|
222
+ desc "get_attachment_of_in <incident> <filename>", "download an attachment of an Incident and print it out on stdout"
223
+ def get_attachment_of_in(incident, filename)
224
+ att_in = loadcon.search("lrel_attachments_requests",{'fields' => "attmnt","wc" => "cr.ref_num = '#{incident}'"})
225
+ att_in.each do |att|
202
226
  attmnt = loadcon.request("/caisd-rest/attmnt/#{att["attmnt"]["@id"]}")["attmnt"]
203
227
  if attmnt["orig_file_name"] == filename
204
228
  puts loadcon.request("/caisd-rest/attmnt/#{attmnt["@id"]}/file-resource",{:unchanged => true})
@@ -206,6 +230,36 @@ class Rusdc < Thor
206
230
  end
207
231
  end
208
232
 
233
+ desc "get_attachment_of_co <co_name> <filename>", "download an attachment of a changeorder and print it out on stdout"
234
+ def get_attachment_of_co(coname, filename)
235
+ ids = loadcon.search("lrel_attachments_changes",{'fields' => "*","wc" => "chg.chg_ref_num = 'CO341144' and attmnt.orig_file_name = 'IMAP61A845F524A9D06536_3212.eml'"})
236
+ puts loadcon.request("/caisd-rest/attmnt/#{ids[0]["@id"]}/file-resource",{:unchanged => true}) if ids.class == Array
237
+ end
238
+
239
+ desc "in_add_attachment <in> <file>", "attach the file to incident"
240
+ def in_add_attachment(incident, file)
241
+ response = loadcon.upload_attachment(file)
242
+ puts response
243
+ data = JSON.parse(response)
244
+ template = ERB.new <<-EOF
245
+ {
246
+ "lrel_attachments_requests": {
247
+ "attmnt": {
248
+ "@id": "<%= id %>"
249
+ },
250
+ "cr": {
251
+ "@COMMON_NAME": "<%= incident %>"
252
+ }
253
+ }
254
+ }
255
+ EOF
256
+ json = template.result_with_hash({
257
+ :id => data["attmnt"]["@id"],
258
+ :incident => incident
259
+ })
260
+ puts loadcon.create({:type => "json", :data => json})
261
+ end
262
+
209
263
  desc "in_add_2_chg <changeorder> <incident>", "add incident to changeorder"
210
264
  def in_add_2_chg(chg, incident)
211
265
  invoke('update_ref_attr',['in', incident, 'change', chg])
@@ -227,12 +281,46 @@ class Rusdc < Thor
227
281
  desc "list_attachments_of_co <co_name>", "list all attachments of a changeorder"
228
282
  def list_attachments_of_co(coname)
229
283
  chg_id=loadcon.request("/caisd-rest/chg/COMMON_NAME-#{coname}")["chg"]["@id"]
230
- att_nr = loadcon.search("lrel_attachments_changes",{'fields' => "attmnt","wc" => "chg = #{chg_id}"})
231
- att_nr.each do |att|
284
+ att_chg = loadcon.search("lrel_attachments_changes",{'fields' => "attmnt","wc" => "chg = #{chg_id}"})
285
+ att_chg.each do |att|
232
286
  puts loadcon.request("/caisd-rest/attmnt/#{att["attmnt"]["@id"]}")["attmnt"]["orig_file_name"]
233
287
  end
234
288
  end
235
289
 
290
+ desc "list_attachments_of_in <in>", "list all attachments of an Incident"
291
+ def list_attachments_of_in(incident)
292
+ att_in = loadcon.search("lrel_attachments_requests",{'fields' => "attmnt","wc" => "cr.ref_num = '#{incident}'"})
293
+ att_in.each do |att|
294
+ puts loadcon.request("/caisd-rest/attmnt/#{att["attmnt"]["@id"]}")["attmnt"]["orig_file_name"]
295
+ end
296
+ end
297
+
298
+ desc "nr_add_attachment <nr> <file>", "attach the file to nr"
299
+ def nr_add_attachment(nr, file)
300
+ response = loadcon.upload_attachment(file)
301
+ puts response
302
+ data = JSON.parse(response)
303
+ nr_id = loadcon.search("nr",{'fields' => "@id","wc" => "name = '#{nr}'"})[0]["@id"]
304
+ template = ERB.new <<-EOF
305
+ {
306
+ "lrel_attachments_nr": {
307
+ "attmnt": {
308
+ "@id": "<%= id %>"
309
+ },
310
+ "nr": {
311
+ "@id": "<%= nr_id %>"
312
+ }
313
+ }
314
+ }
315
+ EOF
316
+ json = template.result_with_hash({
317
+ :id => data["attmnt"]["@id"],
318
+ :nr_id => nr_id
319
+ })
320
+ #puts "create relation to chg with json: #{json}"
321
+ puts loadcon.create({:type => "json", :data => json})
322
+ end
323
+
236
324
  desc "nr_add_child <nr-name> <child-name>", "add one child CI to another CI"
237
325
  def nr_add_child(nr, child)
238
326
  template = ERB.new <<-EOF
@@ -406,7 +494,7 @@ class Rusdc < Thor
406
494
  if data.class == RestClient::BadRequest
407
495
  puts "BadRequest-Response from USD-API, try to update via IDs. be aware to specify a ref_obj if it's not nr."
408
496
  cn_id = loadcon.search(obj,{'fields' => "@id","wc" => "#{Usd::CN[obj]} = '#{cn}' and delete_flag = 0"})[0]["@id"]
409
- value_id = loadcon.search(ref_obj,{'fields' => "@id","wc" => "#{Usd::CN[obj]} = '#{v}' and delete_flag = 0"})[0]["@id"]
497
+ value_id = loadcon.search(ref_obj,{'fields' => "@id","wc" => "#{Usd::CN[ref_obj]} = '#{v}' and delete_flag = 0"})[0]["@id"]
410
498
  invoke "update_ref_attr_by_id", [obj, cn_id, k, value_id]
411
499
  else
412
500
  puts data
@@ -434,6 +522,36 @@ class Rusdc < Thor
434
522
  puts loadcon.update({:type => "json", :data => json})
435
523
  end
436
524
 
525
+ desc "vcard_via_email <email>", "creates a vcard from the given email-address and saves it in the /tmp directory."
526
+ def vcard_via_email(email)
527
+ cnt = loadcon.search("cnt",{'fields' => "*","wc" => "email_address = '#{email}' and delete_flag = 0"})[0]
528
+ template = ERB.new <<-EOF
529
+ BEGIN:VCARD
530
+ VERSION:2.1
531
+ N;LANGUAGE=de:;<%= last_name %>;<%= first_name %>
532
+ FN:<%= last_name %>, <%= first_name %>
533
+ TEL;WORK;VOICE:<%= phone_number %>
534
+ TEL;CELL;VOICE:<%= mobile_phone %>
535
+ EMAIL;PREF;INTERNET:<%= email_address %>
536
+ X-MS-OL-DEFAULT-POSTAL-ADDRESS:0
537
+ X-MS-OL-DESIGN;CHARSET=utf-8:<card xmlns="http://schemas.microsoft.com/office/outlook/12/electronicbusinesscards" ver="1.0" layout="left" bgcolor="ffffff"><img xmlns="" align="fit" area="16" use="cardpicture"/><fld xmlns="" prop="name" align="left" dir="ltr" style="b" color="000000" size="10"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="telwork" align="left" dir="ltr" color="d48d2a" size="8"><label align="right" color="626262">Geschäftlich</label></fld><fld xmlns="" prop="telcell" align="left" dir="ltr" color="d48d2a" size="8"><label align="right" color="626262">Mobiltelefon</label></fld><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="blank" size="8"/></card>
538
+ REV:<%= time %>
539
+ END:VCARD
540
+ EOF
541
+ vcard=template.result_with_hash({
542
+ :last_name => cnt["last_name"],
543
+ :first_name => cnt["first_name"],
544
+ :email_address => cnt["email_address"],
545
+ :phone_number => cnt["phone_number"],
546
+ :mobile_phone => cnt["mobile_phone"],
547
+ :time => Time.now.strftime("%Y%m%dT%H%M%SZ")
548
+ })
549
+ file = `mktemp /tmp/#{cnt["last_name"]}-XXXXX.vcf`.chop
550
+ f = File.open(file,"w+")
551
+ f.puts vcard
552
+ f.close
553
+ puts "the vcard for #{cnt["first_name"]} #{cnt["last_name"]} was created under: #{file}"
554
+ end
437
555
 
438
556
  private
439
557
 
@@ -1,5 +1,31 @@
1
1
  # rusdc changelog
2
2
 
3
+ ## 1.3.4.1
4
+
5
+ - fixed another error in Usd.search. which comes with 1.3.1 .
6
+
7
+ ## 1.3.4
8
+
9
+ - move function `upload_attachment` from `bin/rusdc` to `lib/usd`.
10
+
11
+ ## 1.3.3
12
+
13
+ - private `rusdc`-funktion `upload_attachment` changed. Instead using `base64` and `unix2dos` binaries, we use Base64-Ruby-Class now. It is already required by usd.
14
+
15
+ ## 1.3.2
16
+
17
+ - fixed error in Usd.search. which comes with 1.3.1 .
18
+
19
+ ## 1.3.1
20
+
21
+ - new functions:
22
+ - `chg_add_attachment`
23
+ - `nr_add_attachment`
24
+ - `in_add_attachment`
25
+ - `vcard_via_email`
26
+
27
+ with the first three funtions you are able to upload files to changeorders, configurationitems and incidents and it does not matter if it is text or binary. the last new function creates vcards in version 2.1 from a contact via its email as identifier.
28
+
3
29
  ## 1.2
4
30
 
5
31
  - now in Usd.search function:
Binary file
data/lib/usd.rb CHANGED
@@ -251,7 +251,7 @@ class Usd
251
251
  # if wc contains no sql-compare operater, it will be changed to "COMMON_NAME like '%<wc-before>%'"
252
252
  wc = attr.pop
253
253
  wc.gsub!(/^WC=/,'')
254
- if ([" like ","<",">","="," is "].find {|e| wc =~ /#{e}/}).nil?
254
+ if ([" like ","<",">","="," is "," in "," LIKE ", " IS ", " IN "].find {|e| wc =~ /#{e}/}).nil?
255
255
  wc = "#{CN[object]} like '%#{wc}%'"
256
256
  end
257
257
  attr.push "WC=#{wc}"
@@ -279,6 +279,26 @@ class Usd
279
279
  end
280
280
  end
281
281
 
282
+ def upload_attachment(file, baseurl = @base_url, ak = @access_key)
283
+ baseurl =~ /^([^:]+):/
284
+ server = $1
285
+ filename = File.basename(file)
286
+ uri = "/caisd-rest/attmnt?repositoryId=1002&serverName=#{server}&mimeType=Text&description=#{filename}"
287
+ url = URI("#{baseurl}#{uri}")
288
+ http = Net::HTTP.new(url.host, url.port);
289
+ request = Net::HTTP::Post.new(url)
290
+ request["X-AccessKey"] = ak
291
+ request["Content-Type"] = "multipart/form-data; BOUNDARY=*****MessageBoundary*****"
292
+ request["accept"] = "application/json"
293
+ request["Cache-Control"] = "no-cache"
294
+ fileObj = File.open(file, "rb")
295
+ fileContent = fileObj.read
296
+ fileObj.close
297
+ request.body = "--*****MessageBoundary*****\r\n \r\nContent-Disposition: form-data; name=\"payload\" \r\nContent-Type: application/xml; CHARACTERSET=UTF-8 \r\n\r\n \r\n<attmnt> \r\n<repository id=\"1002\"></repository> \r\n<orig_file_name>#{filename}</orig_file_name> \r\n<attmnt_name>#{filename}</attmnt_name> \r\n<description>Uploaded with rusdc from rubygem usd</description> \r\n</attmnt> \r\n\r\n \r\n--*****MessageBoundary*****\r\n \r\nContent-Disposition: form-data; name=\"#{filename}\"; filename=\"#{filename}\" \r\nContent-Type: application/octet-stream \r\nContent-Transfer-Encoding: base64\r\n\r\n#{Base64.encode64(fileContent)}\r\n\r\n \r\n--*****MessageBoundary*****--\r\n"
298
+ response = http.request(request)
299
+ response.read_body
300
+ end
301
+
282
302
  end
283
303
 
284
304
  module Jsonpretty
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'usd'
3
- spec.version = '1.2'
4
- spec.date = '2020-09-02'
3
+ spec.version = '1.3.4.1'
4
+ spec.date = '2020-09-11'
5
5
  spec.summary = "SDM REST-API-Calls"
6
6
  spec.description = "a Ruby class and a commandlinetool for SDM REST-API-Calls"
7
7
  spec.authors = ["Oliver Gaida"]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usd
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.2'
4
+ version: 1.3.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oliver Gaida
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-02 00:00:00.000000000 Z
11
+ date: 2020-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -82,6 +82,7 @@ files:
82
82
  - bin/rusdc
83
83
  - bin/set_env
84
84
  - change_log.md
85
+ - images/vcard.png
85
86
  - lib/usd.rb
86
87
  - usd.gemspec
87
88
  homepage: https://github.com/ogaida/usd