bcl 0.3.4 → 0.3.5

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.
@@ -42,6 +42,7 @@ module BCL
42
42
  def initialize()
43
43
  @config = nil
44
44
  @session = nil
45
+ @access_token = nil
45
46
  @http = nil
46
47
  @api_version = 2.0
47
48
  config_path = File.expand_path('~') + '/.bcl'
@@ -94,10 +95,10 @@ module BCL
94
95
  data = %Q({"username":"#{username}","password":"#{password}"})
95
96
  #data = {"username" => username, "password" => password}
96
97
 
97
- path = "/api/user/login.json?"
98
+ login_path = "/api/user/login.json?"
98
99
  headers = {'Content-Type' => 'application/json'}
99
100
 
100
- res, data = @http.post(path, data, headers)
101
+ res, data = @http.post(login_path, data, headers)
101
102
 
102
103
  #restClient wasn't working
103
104
  #res = RestClient.post "#{@config[:server][:url]}/api/user/login", data.to_json, :content_type => :json, :accept => :json
@@ -134,7 +135,7 @@ module BCL
134
135
  @session = {session_name => sessid,bnes_name => bnesid,bni_name => bni_id}
135
136
 
136
137
  =end
137
-
138
+
138
139
  bnes = ""
139
140
  bni = ""
140
141
  junkout = res["set-cookie"].split(";")
@@ -162,9 +163,24 @@ module BCL
162
163
  end
163
164
  end
164
165
 
165
- @session = session_name + '=' + sessid + ';' + bni + ";" + bnes
166
-
167
- #puts "SESSION COOKIE: #{@session}"
166
+ @session = session_name + '=' + sessid + ';' + bni + ";" + bnes
167
+
168
+ #get access token
169
+ token_path = "/services/session/token"
170
+ token_headers = {'Content-Type' => 'application/json', 'Cookie' => @session}
171
+ #puts "token_headers = #{token_headers.inspect}"
172
+ access_token_res, access_token = @http.post(token_path,"",token_headers)
173
+ if access_token_res.code == '200'
174
+ @access_token = access_token
175
+ else
176
+ puts "Unable to get access token; uploads will not work"
177
+ puts "error code: #{access_token_res.code}"
178
+ puts "error info: #{access_token_res.body}"
179
+ end
180
+
181
+ #puts "access_token = *#{@access_token}*"
182
+ #puts "cookie = #{@session}"
183
+
168
184
  res
169
185
  else
170
186
 
@@ -179,6 +195,7 @@ module BCL
179
195
  # username and password set in ~/.bcl/config.yml file
180
196
  def push_content(filename_and_path, write_receipt_file, content_type, bcl_group_id)
181
197
  raise "Please login before pushing components" if @session.nil?
198
+ raise "Do not have a valid access token; try again" if @access_token.nil?
182
199
  valid = false
183
200
  res_j = nil
184
201
  filename = File.basename(filename_and_path)
@@ -197,6 +214,10 @@ module BCL
197
214
  "node" =>
198
215
  {
199
216
  "type" => "#{content_type}",
217
+ "field_component_tags" => #TODO remove this field_component_tags once BCL is fixed
218
+ {
219
+ "und" => "1289"
220
+ },
200
221
  "og_group_ref" =>
201
222
  {
202
223
  "und" =>
@@ -209,8 +230,8 @@ module BCL
209
230
  #res = RestClient.post "#{@config[:server][:url]}/api/content.json", @data.to_json, :content_type => :json, :cookies => @session
210
231
 
211
232
  path = "/api/content.json"
212
- headers = {'Content-Type' => 'application/json', 'Cookie' => @session}
213
-
233
+ headers = {'Content-Type' => 'application/json','X-CSRF-Token' => @access_token, 'Cookie' => @session}
234
+ #puts headers.inspect
214
235
  res, data = @http.post(path, @data.to_json, headers)
215
236
 
216
237
  res_j = "could not get json from http post response"
@@ -288,6 +309,10 @@ module BCL
288
309
  "node" =>
289
310
  {
290
311
  "uuid" => "#{uuid}",
312
+ "field_component_tags" => #TODO remove this field_component_tags once BCL is fixed
313
+ {
314
+ "und" => "1289"
315
+ },
291
316
  "og_group_ref" =>
292
317
  {
293
318
  "und" =>
@@ -301,7 +326,7 @@ module BCL
301
326
  #res = RestClient.post "#{@config[:server][:url]}/api/content", @data.to_json, :content_type => :json, :cookies => @session, :accept => :json
302
327
 
303
328
  path = "/api/content.json"
304
- headers = {'Content-Type' => 'application/json', 'Cookie' => @session}
329
+ headers = {'Content-Type' => 'application/json', 'Cookie' => @session, 'X-CSRF-Token' => @access_token}
305
330
 
306
331
  res, data = @http.post(path, @data.to_json, headers)
307
332
 
@@ -23,6 +23,7 @@
23
23
  require 'rubygems'
24
24
  require 'pathname'
25
25
  require 'fileutils'
26
+ require 'date'
26
27
 
27
28
  # required gems
28
29
  require 'uuid' # gem install uuid
@@ -55,7 +56,7 @@ class ComponentSpreadsheet
55
56
  if $have_win32ole
56
57
 
57
58
  #initialize with Excel spreadsheet to read
58
- def initialize(xlsx_path,worksheet_names = "all")
59
+ def initialize(xlsx_path,worksheet_names =["all"])
59
60
 
60
61
  @xlsx_path = Pathname.new(xlsx_path).realpath.to_s
61
62
  @worksheets = []
@@ -67,7 +68,7 @@ if $have_win32ole
67
68
  xlsx = excel.Workbooks.Open(@xlsx_path)
68
69
 
69
70
  #by default, operate on all worksheets
70
- if worksheet_names == "all"
71
+ if worksheet_names == ["all"]
71
72
  xlsx.Worksheets.each do |xlsx_worksheet|
72
73
  parse_xlsx_worksheet(xlsx_worksheet)
73
74
  end
@@ -144,6 +145,13 @@ end # if $have_win32ole
144
145
 
145
146
  author = values.delete_at(0)
146
147
  datetime = values.delete_at(0)
148
+ if datetime.nil?
149
+ puts "[ComponentSpreadsheet] WARNING missing the date in the datetime column in the spreadsheet - assuming today"
150
+ datetime = DateTime.new
151
+ else
152
+ datetime = DateTime.parse(datetime)
153
+ end
154
+
147
155
  comment = values.delete_at(0)
148
156
  component_xml.add_provenance(author.to_s, datetime.to_s, comment.to_s)
149
157
 
@@ -270,6 +278,8 @@ end # if $have_win32ole
270
278
  headers[0].name = "description"
271
279
  end
272
280
 
281
+ puts " Found #{num_rows - 2} components"
282
+
273
283
  components = []
274
284
  for i in 3..num_rows do
275
285
  component = ComponentStruct.new
@@ -289,6 +289,8 @@ module BCL
289
289
  comp_xml.description @description if @description != ""
290
290
  comp_xml.comment @comment if @comment != ""
291
291
 
292
+ comp_xml.fidelity_level @fidelity_level if @fidelity_level != ""
293
+
292
294
  comp_xml.provenances {
293
295
  @provenances.each do |prov|
294
296
  comp_xml.provenance {
Binary file