etna 0.1.22 → 0.1.23

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c3726db5513bc41e2909cbf25597ad3c83b3cb50c599fbf3f37e3efde11d47f
4
- data.tar.gz: 8635c884833e3f403335c94f183609c6613e825964279dce349e145050eac0c1
3
+ metadata.gz: 6ae7868eeaa6de2a8701602929e642d381ccab2115c71cb18c216a362217645c
4
+ data.tar.gz: 9183c39484f21c330f1c0e14f4c9e355e8302805f71dbdbb5889f1e3eeb58bb4
5
5
  SHA512:
6
- metadata.gz: 5d19841e9c12cca76030dfde0322c9e6e221d8799c13088bee0897db18acba38c04e1ae6841db8a04766136639f5a445cc286114e77f0747ab405c0f8aca0652
7
- data.tar.gz: cff82b91e49e07100d7350444b034abccfbfa2e28e6e6cc9928097dd7317c263f4870dc6eca0164451f0759b12a358d7db13d441e8ebe9c2c1b0e287b684ce73
6
+ metadata.gz: 20ae9fdf11e4da6e000be9308e5c3f8b5309d219aa5820b4a855ee43b80d2f4c6bc7f33e52e1844ab3bfe02ee67968cbb91f53737a0a6515ba870b08dffe854e
7
+ data.tar.gz: a43573a1a801e9d4be0aee3390997b68507b6bdcb626fc185264eb8cb884b7e14d92a4485df5ec494527bd8609d761a7f7e1ca5c9064181789506e756f8d4157
@@ -136,7 +136,7 @@ all_flag_completion_names="$all_flag_completion_names "
136
136
  string_flag_completion_names="$string_flag_completion_names "
137
137
  while [[ "$#" != "0" ]]; do
138
138
  if [[ "$#" == "1" ]]; then
139
- all_completion_names="create_file_linking_csv help update_from_csv"
139
+ all_completion_names="create_file_linking_csv help load_table_from_csv update_from_csv"
140
140
  all_completion_names="$all_completion_names $all_flag_completion_names"
141
141
  if [[ -z "$(echo $all_completion_names | xargs)" ]]; then
142
142
  return
@@ -252,6 +252,68 @@ return
252
252
  fi
253
253
  done
254
254
  return
255
+ elif [[ "$1" == "load_table_from_csv" ]]; then
256
+ shift
257
+ if [[ "$#" == "1" ]]; then
258
+ all_completion_names="__project_name__"
259
+ if [[ -z "$(echo $all_completion_names | xargs)" ]]; then
260
+ return
261
+ fi
262
+ COMPREPLY=($(compgen -W "$all_completion_names" -- "$1"))
263
+ return
264
+ fi
265
+ shift
266
+ if [[ "$#" == "1" ]]; then
267
+ all_completion_names="__model_name__"
268
+ if [[ -z "$(echo $all_completion_names | xargs)" ]]; then
269
+ return
270
+ fi
271
+ COMPREPLY=($(compgen -W "$all_completion_names" -- "$1"))
272
+ return
273
+ fi
274
+ shift
275
+ if [[ "$#" == "1" ]]; then
276
+ all_completion_names="__file_path__"
277
+ if [[ -z "$(echo $all_completion_names | xargs)" ]]; then
278
+ return
279
+ fi
280
+ COMPREPLY=($(compgen -W "$all_completion_names" -- "$1"))
281
+ return
282
+ fi
283
+ shift
284
+ all_flag_completion_names="$all_flag_completion_names --execute "
285
+ string_flag_completion_names="$string_flag_completion_names "
286
+ while [[ "$#" != "0" ]]; do
287
+ if [[ "$#" == "1" ]]; then
288
+ all_completion_names=""
289
+ all_completion_names="$all_completion_names $all_flag_completion_names"
290
+ if [[ -z "$(echo $all_completion_names | xargs)" ]]; then
291
+ return
292
+ fi
293
+ COMPREPLY=($(compgen -W "$all_completion_names" -- "$1"))
294
+ return
295
+ elif [[ -z "$(echo $all_flag_completion_names | xargs)" ]]; then
296
+ return
297
+ elif [[ "$all_flag_completion_names" =~ $1\ ]]; then
298
+ all_flag_completion_names="${all_flag_completion_names//$1\ /}"
299
+ a=$1
300
+ shift
301
+ if [[ "$string_flag_completion_names" =~ $a\ ]]; then
302
+ if [[ "$#" == "1" ]]; then
303
+ a="${a//--/}"
304
+ a="${a//-/_}"
305
+ i="_completions_for_$a"
306
+ all_completion_names="${!i}"
307
+ COMPREPLY=($(compgen -W "$all_completion_names" -- "$1"))
308
+ return
309
+ fi
310
+ shift
311
+ fi
312
+ else
313
+ return
314
+ fi
315
+ done
316
+ return
255
317
  elif [[ "$1" == "update_from_csv" ]]; then
256
318
  shift
257
319
  if [[ "$#" == "1" ]]; then
@@ -54,15 +54,16 @@ class EtnaApp
54
54
  boolean_flags << '--ignore-ssl'
55
55
 
56
56
  def execute(host, ignore_ssl: false)
57
- polyphemus_client ||= Etna::Clients::Polyphemus.new(
57
+ polyphemus_client = Etna::Clients::Polyphemus.new(
58
58
  host: host,
59
59
  token: token(ignore_environment: true),
60
+ persistent: false,
60
61
  ignore_ssl: ignore_ssl)
61
62
  workflow = Etna::Clients::Polyphemus::SetConfigurationWorkflow.new(
62
63
  polyphemus_client: polyphemus_client,
63
64
  config_file: EtnaApp.config_file_path)
64
65
  config = workflow.update_configuration_file(ignore_ssl: ignore_ssl)
65
- logger.info("Updated #{config.environment} configuration from #{host}.")
66
+ logger&.info("Updated #{config.environment} configuration from #{host}.")
66
67
  end
67
68
 
68
69
  def setup(config)
@@ -299,6 +300,49 @@ class EtnaApp
299
300
  workflow.write_csv_io(filename: file)
300
301
  end
301
302
  end
303
+
304
+ class LoadTableFromCsv < Etna::Command
305
+ include WithEtnaClients
306
+
307
+ boolean_flags << '--execute'
308
+
309
+ def execute(project_name, model_name, file_path, execute: false)
310
+ request = Etna::Clients::Magma::RetrievalRequest.new(project_name: project_name)
311
+ request.model_name = model_name
312
+ request.attribute_names = 'all'
313
+ request.record_names = 'all'
314
+ model = magma_client.retrieve(request).models.model(model_name)
315
+ model_parent_name = model.template.attributes.all.select do |attribute|
316
+ attribute.attribute_type == Etna::Clients::Magma::AttributeType::PARENT
317
+ end.first.name
318
+
319
+ other_attribute_names = model.template.attributes.all.reject do |attribute|
320
+ attribute.attribute_type == Etna::Clients::Magma::AttributeType::PARENT
321
+ end.map do |attribute|
322
+ attribute.name
323
+ end
324
+
325
+ # NOTE: This does not call ensure_parent currently because of MVIR1 consent--
326
+ # if the timepoint doesn't exist, the patient may be no study? (one example, at least)
327
+ update_request = Etna::Clients::Magma::UpdateRequest.new(project_name: project_name)
328
+
329
+ data = CSV.parse(File.read(file_path), headers: true)
330
+
331
+ data.by_row.each do |row|
332
+ revision = {}
333
+ other_attribute_names.each do |attribute_name|
334
+ revision[attribute_name] = row[attribute_name] unless row[attribute_name].nil?
335
+ end
336
+ update_request.append_table(model_parent_name, row[model_parent_name], model_name, revision)
337
+ end
338
+
339
+ puts update_request
340
+
341
+ if execute
342
+ magma_client.update_json(update_request)
343
+ end
344
+ end
345
+ end
302
346
  end
303
347
  end
304
348
  end
@@ -30,6 +30,8 @@ def setup_base_vcr(spec_helper_dir)
30
30
  end
31
31
  end
32
32
 
33
+ # c.debug_logger = File.open('log/vcr_debug.log', 'w')
34
+
33
35
  c.default_cassette_options = {
34
36
  serialize_with: :compressed,
35
37
  record: if ENV['IS_CI'] == '1'
@@ -82,6 +84,11 @@ def setup_base_vcr(spec_helper_dir)
82
84
  end
83
85
  end
84
86
  end
87
+
88
+ require 'multipartable'
89
+ def Multipartable.secure_boundary
90
+ "--THIS-IS-STABLE-FOR-TESTING"
91
+ end
85
92
  end
86
93
 
87
94
  def prepare_vcr_secret
@@ -6,6 +6,15 @@ module WithEtnaClients
6
6
  EtnaApp.instance.environment
7
7
  end
8
8
 
9
+ def exit(status=true)
10
+ WithEtnaClients.exit(status)
11
+ end
12
+
13
+ # Abstraction used to prevent accidental exist in specs.
14
+ def self.exit(status)
15
+ Kernel.exit(status)
16
+ end
17
+
9
18
  def token(ignore_environment: false)
10
19
  unless ignore_environment
11
20
  if environment == :many
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etna
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.22
4
+ version: 0.1.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saurabh Asthana
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-15 00:00:00.000000000 Z
11
+ date: 2020-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -117,6 +117,7 @@ files:
117
117
  - lib/etna/clients/magma/workflows/file_linking_workflow.rb
118
118
  - lib/etna/clients/magma/workflows/json_converters.rb
119
119
  - lib/etna/clients/magma/workflows/json_validators.rb
120
+ - lib/etna/clients/magma/workflows/materialize_magma_record_files_workflow.rb
120
121
  - lib/etna/clients/magma/workflows/model_synchronization_workflow.rb
121
122
  - lib/etna/clients/magma/workflows/record_synchronization_workflow.rb
122
123
  - lib/etna/clients/magma/workflows/update_attributes_from_csv_workflow.rb