etna 0.1.33 → 0.1.34
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 +4 -4
- data/lib/etna/clients/magma/formatting/models_csv.rb +5 -6
- data/lib/etna/clients/magma/formatting/models_odm_xml.rb +1 -1
- data/lib/etna/clients/magma/models.rb +15 -28
- data/lib/etna/clients/magma/workflows/model_synchronization_workflow.rb +1 -4
- data/lib/etna/clients/magma/workflows/walk_model_tree_workflow.rb +59 -11
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ccfc9ac71071c9d8a8307849c585a388e983a4d5a44ca644f63a0501d7c758b6
|
|
4
|
+
data.tar.gz: ae4b4fb56594d585c9a5cc8267edac39af8718efb5f33b57e59b75e61ad38d5d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b146fcb1b3484943d63a6a365127b968738601816a566730e9292e2a73ae7c4e855042c0d7522c3ff896dbc3ab6aa817eb7edc6a5e8af12a4ffd1011da13d2bc
|
|
7
|
+
data.tar.gz: 1d29823e63c48b159e980ee05349505b8a43271a1593a6084771b22952b4efa919ba2d285e70140e24fde29bbdb6ca5e8c216144e8e15810a622acd6960561f7
|
|
@@ -138,7 +138,7 @@ module Etna
|
|
|
138
138
|
attribute_type: attribute.attribute_type,
|
|
139
139
|
link_model_name: attribute.link_model_name,
|
|
140
140
|
reciprocal_link_type: models.find_reciprocal(model: model, attribute: attribute)&.attribute_type,
|
|
141
|
-
description: attribute.
|
|
141
|
+
description: attribute.description,
|
|
142
142
|
display_name: attribute.display_name,
|
|
143
143
|
match: attribute.match,
|
|
144
144
|
format_hint: attribute.format_hint,
|
|
@@ -175,7 +175,7 @@ module Etna
|
|
|
175
175
|
# This should line up with the attribute names _on the model itself_.
|
|
176
176
|
ATTRIBUTE_ROW_ENTRIES = [
|
|
177
177
|
:attribute_type,
|
|
178
|
-
:link_model_name, :
|
|
178
|
+
:link_model_name, :description,
|
|
179
179
|
:display_name, :format_hint,
|
|
180
180
|
:restricted, :read_only,
|
|
181
181
|
:validation, :attribute_group,
|
|
@@ -188,7 +188,6 @@ module Etna
|
|
|
188
188
|
|
|
189
189
|
def format_row(row)
|
|
190
190
|
replace_row_column(row, :attribute_type) { |s| AttributeType.new(s) }
|
|
191
|
-
replace_row_column(row, :desc) { row.delete(:description) }
|
|
192
191
|
replace_row_column(row, :restricted, &COLUMN_AS_BOOLEAN)
|
|
193
192
|
replace_row_column(row, :read_only, &COLUMN_AS_BOOLEAN)
|
|
194
193
|
replace_row_column(row, :options) { |s| {"type" => "Array", "value" => s.split(',').map(&:strip)} }
|
|
@@ -250,7 +249,7 @@ module Etna
|
|
|
250
249
|
parent_att.name = parent_att.attribute_name = parent_model_name
|
|
251
250
|
parent_att.attribute_type = Etna::Clients::Magma::AttributeType::PARENT
|
|
252
251
|
parent_att.link_model_name = parent_model_name
|
|
253
|
-
parent_att.
|
|
252
|
+
parent_att.description = prettify(parent_model_name)
|
|
254
253
|
parent_att.display_name = prettify(parent_model_name)
|
|
255
254
|
end
|
|
256
255
|
end
|
|
@@ -275,7 +274,7 @@ module Etna
|
|
|
275
274
|
attr.attribute_name = attr.name = template.name
|
|
276
275
|
attr.attribute_type = parent_link_type
|
|
277
276
|
attr.link_model_name = template.name
|
|
278
|
-
attr.
|
|
277
|
+
attr.description = prettify(template.name)
|
|
279
278
|
attr.display_name = prettify(template.name)
|
|
280
279
|
end
|
|
281
280
|
end
|
|
@@ -338,7 +337,7 @@ module Etna
|
|
|
338
337
|
models.build_model(att.link_model_name).build_template.build_attributes.build_attribute(template.name).tap do |rec_att|
|
|
339
338
|
rec_att.attribute_name = rec_att.name = template.name
|
|
340
339
|
rec_att.display_name = prettify(template.name)
|
|
341
|
-
rec_att.
|
|
340
|
+
rec_att.description = prettify(template.name)
|
|
342
341
|
rec_att.attribute_type = Etna::Clients::Magma::AttributeType::COLLECTION
|
|
343
342
|
rec_att.link_model_name = template.name
|
|
344
343
|
end
|
|
@@ -246,7 +246,7 @@ module Etna
|
|
|
246
246
|
}
|
|
247
247
|
|
|
248
248
|
params['redcap:TextValidationType'] = redcap_text_validation_map[attribute_type] if redcap_text_validation_map[attribute_type]
|
|
249
|
-
params['redcap:FieldNote'] = attribute.
|
|
249
|
+
params['redcap:FieldNote'] = attribute.description if attribute.description
|
|
250
250
|
xml.ItemDef(params) do
|
|
251
251
|
xml.Question do
|
|
252
252
|
xml.send('TranslatedText', attribute_name.capitalize)
|
|
@@ -10,7 +10,7 @@ require_relative '../base_client'
|
|
|
10
10
|
module Etna
|
|
11
11
|
module Clients
|
|
12
12
|
class Magma < Etna::Clients::BaseClient
|
|
13
|
-
class RetrievalRequest < Struct.new(:model_name, :attribute_names, :record_names, :project_name, :page, :page_size, :order, :filter, keyword_init: true)
|
|
13
|
+
class RetrievalRequest < Struct.new(:model_name, :attribute_names, :record_names, :project_name, :page, :page_size, :order, :filter, :hide_templates, keyword_init: true)
|
|
14
14
|
include JsonSerializableStruct
|
|
15
15
|
|
|
16
16
|
def initialize(**params)
|
|
@@ -18,7 +18,7 @@ module Etna
|
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
class QueryRequest < Struct.new(:query, :project_name, keyword_init: true)
|
|
21
|
+
class QueryRequest < Struct.new(:query, :project_name, :order, :page, :page_size, keyword_init: true)
|
|
22
22
|
include JsonSerializableStruct
|
|
23
23
|
end
|
|
24
24
|
|
|
@@ -117,14 +117,6 @@ module Etna
|
|
|
117
117
|
super({action_name: 'update_attribute'}.update(args))
|
|
118
118
|
end
|
|
119
119
|
|
|
120
|
-
def desc=(val)
|
|
121
|
-
self.description = val
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
def desc
|
|
125
|
-
self.description
|
|
126
|
-
end
|
|
127
|
-
|
|
128
120
|
def as_json
|
|
129
121
|
super(keep_nils: true)
|
|
130
122
|
end
|
|
@@ -454,6 +446,16 @@ module Etna
|
|
|
454
446
|
@raw = raw
|
|
455
447
|
end
|
|
456
448
|
|
|
449
|
+
def is_edited?(other)
|
|
450
|
+
# Don't just override == in case need to do a full comparison.
|
|
451
|
+
editable_attribute_names = Attribute::EDITABLE_ATTRIBUTE_ATTRIBUTES.map(&:to_s)
|
|
452
|
+
|
|
453
|
+
self_editable = raw.slice(*editable_attribute_names)
|
|
454
|
+
other_editable = other.raw.slice(*editable_attribute_names)
|
|
455
|
+
|
|
456
|
+
self_editable != other_editable
|
|
457
|
+
end
|
|
458
|
+
|
|
457
459
|
# Sets certain attribute fields which are implicit, even when not set, to match server behavior.
|
|
458
460
|
def set_field_defaults!
|
|
459
461
|
@raw.replace({
|
|
@@ -511,24 +513,12 @@ module Etna
|
|
|
511
513
|
raw['unique'] = val
|
|
512
514
|
end
|
|
513
515
|
|
|
514
|
-
def desc
|
|
515
|
-
raw['desc']
|
|
516
|
-
end
|
|
517
|
-
|
|
518
|
-
def desc=(val)
|
|
519
|
-
@raw['desc'] = val
|
|
520
|
-
end
|
|
521
|
-
|
|
522
|
-
# description and description= are needed
|
|
523
|
-
# to make UpdateAttribute actions
|
|
524
|
-
# work in the model_synchronization_workflow for
|
|
525
|
-
# desc.
|
|
526
516
|
def description
|
|
527
|
-
raw['
|
|
517
|
+
raw['description']
|
|
528
518
|
end
|
|
529
519
|
|
|
530
520
|
def description=(val)
|
|
531
|
-
@raw['
|
|
521
|
+
@raw['description'] = val
|
|
532
522
|
end
|
|
533
523
|
|
|
534
524
|
def display_name
|
|
@@ -595,11 +585,8 @@ module Etna
|
|
|
595
585
|
raw['options']
|
|
596
586
|
end
|
|
597
587
|
|
|
598
|
-
# NOTE! The Attribute class returns description as desc, where as actions take it in as description.
|
|
599
|
-
# There are shortcut methods that try to handle this on the action class side of things. Ideally we would
|
|
600
|
-
# make this more consistent in the near future.
|
|
601
588
|
COPYABLE_ATTRIBUTE_ATTRIBUTES = [
|
|
602
|
-
:attribute_name, :attribute_type, :
|
|
589
|
+
:attribute_name, :attribute_type, :display_name, :format_hint,
|
|
603
590
|
:hidden, :link_model_name, :read_only, :attribute_group, :unique, :validation,
|
|
604
591
|
:restricted, :description
|
|
605
592
|
]
|
|
@@ -190,10 +190,7 @@ module Etna
|
|
|
190
190
|
source_attribute = Attribute.new(source_attribute.raw)
|
|
191
191
|
source_attribute.set_field_defaults!
|
|
192
192
|
|
|
193
|
-
|
|
194
|
-
target_editable = target_attribute.raw.slice(*Attribute::EDITABLE_ATTRIBUTE_ATTRIBUTES.map(&:to_s))
|
|
195
|
-
|
|
196
|
-
if source_editable == target_editable
|
|
193
|
+
if !source_attribute.is_edited?(target_attribute)
|
|
197
194
|
return
|
|
198
195
|
end
|
|
199
196
|
|
|
@@ -12,14 +12,37 @@ module Etna
|
|
|
12
12
|
@template_for = {}
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
+
def all_attributes(template:)
|
|
16
|
+
template.attributes.attribute_keys
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def safe_group_attributes(template:, attributes_mask:)
|
|
20
|
+
result = []
|
|
21
|
+
|
|
22
|
+
template.attributes.attribute_keys.each do |attribute_name|
|
|
23
|
+
next if template.attributes.attribute(attribute_name).attribute_type == Etna::Clients::Magma::AttributeType::TABLE
|
|
24
|
+
result << attribute_name if attribute_included?(attributes_mask, attribute_name)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
result
|
|
28
|
+
end
|
|
29
|
+
|
|
15
30
|
def masked_attributes(template:, model_attributes_mask:, model_name:)
|
|
16
31
|
attributes_mask = model_attributes_mask[model_name]
|
|
17
|
-
|
|
18
|
-
|
|
32
|
+
|
|
33
|
+
if attributes_mask.nil?
|
|
34
|
+
return [
|
|
35
|
+
safe_group_attributes(template: template, attributes_mask: attributes_mask),
|
|
36
|
+
all_attributes(template: template)
|
|
37
|
+
]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
[(safe_group_attributes(template: template, attributes_mask: attributes_mask) + [template.identifier, 'parent']).uniq,
|
|
41
|
+
attributes_mask]
|
|
19
42
|
end
|
|
20
43
|
|
|
21
44
|
def attribute_included?(mask, attribute_name)
|
|
22
|
-
return true if mask
|
|
45
|
+
return true if mask.nil?
|
|
23
46
|
mask.include?(attribute_name)
|
|
24
47
|
end
|
|
25
48
|
|
|
@@ -48,7 +71,11 @@ module Etna
|
|
|
48
71
|
seen.add([path[:from], model_name])
|
|
49
72
|
|
|
50
73
|
template = template_for(model_name)
|
|
51
|
-
query_attributes, walk_attributes = masked_attributes(
|
|
74
|
+
query_attributes, walk_attributes = masked_attributes(
|
|
75
|
+
template: template,
|
|
76
|
+
model_attributes_mask: model_attributes_mask,
|
|
77
|
+
model_name: model_name
|
|
78
|
+
)
|
|
52
79
|
|
|
53
80
|
request = RetrievalRequest.new(
|
|
54
81
|
project_name: magma_crud.project_name,
|
|
@@ -62,6 +89,7 @@ module Etna
|
|
|
62
89
|
related_models = {}
|
|
63
90
|
|
|
64
91
|
magma_crud.page_records(model_name, request) do |response|
|
|
92
|
+
logger&.info("Fetched page of #{model_name}")
|
|
65
93
|
tables = []
|
|
66
94
|
collections = []
|
|
67
95
|
links = []
|
|
@@ -70,13 +98,15 @@ module Etna
|
|
|
70
98
|
model = response.models.model(model_name)
|
|
71
99
|
|
|
72
100
|
template.attributes.attribute_keys.each do |attr_name|
|
|
101
|
+
attr = template.attributes.attribute(attr_name)
|
|
102
|
+
if attr.attribute_type == AttributeType::TABLE && attribute_included?(walk_attributes, attr_name)
|
|
103
|
+
tables << attr_name
|
|
104
|
+
end
|
|
105
|
+
|
|
73
106
|
next unless attribute_included?(query_attributes, attr_name)
|
|
74
107
|
attributes << attr_name
|
|
75
108
|
|
|
76
|
-
attr
|
|
77
|
-
if attr.attribute_type == AttributeType::TABLE
|
|
78
|
-
tables << attr_name
|
|
79
|
-
elsif attr.attribute_type == AttributeType::COLLECTION
|
|
109
|
+
if attr.attribute_type == AttributeType::COLLECTION
|
|
80
110
|
related_models[attr.link_model_name] ||= Set.new
|
|
81
111
|
collections << attr_name
|
|
82
112
|
elsif attr.attribute_type == AttributeType::LINK
|
|
@@ -91,14 +121,32 @@ module Etna
|
|
|
91
121
|
end
|
|
92
122
|
end
|
|
93
123
|
|
|
124
|
+
table_data = {}
|
|
125
|
+
# Request tables in an inner chunk.
|
|
126
|
+
tables.each do |table_attr|
|
|
127
|
+
request = RetrievalRequest.new(
|
|
128
|
+
project_name: magma_crud.project_name,
|
|
129
|
+
model_name: model_name,
|
|
130
|
+
record_names: model.documents.document_keys,
|
|
131
|
+
attribute_names: [table_attr],
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
logger&.info("Fetching inner table #{table_attr}...")
|
|
135
|
+
|
|
136
|
+
table_response = magma_crud.magma_client.retrieve(request)
|
|
137
|
+
d = table_response.models.model(model_name).documents
|
|
138
|
+
table_d = table_response.models.model(table_attr).documents
|
|
139
|
+
table_data[table_attr] = d.document_keys.map do |id|
|
|
140
|
+
[id, d.document(id)[table_attr].map { |tid| table_d.document(tid) }]
|
|
141
|
+
end.to_h
|
|
142
|
+
end
|
|
143
|
+
|
|
94
144
|
model.documents.document_keys.each do |key|
|
|
95
145
|
record = model.documents.document(key).slice(*attributes)
|
|
96
146
|
|
|
97
147
|
# Inline tables inside the record
|
|
98
148
|
tables.each do |table_attr|
|
|
99
|
-
record[table_attr] =
|
|
100
|
-
response.models.model(template.attributes.attribute(table_attr).link_model_name).documents.document(id)
|
|
101
|
-
end unless record[table_attr].nil?
|
|
149
|
+
record[table_attr] = table_data[table_attr][key] unless table_data[table_attr].nil?
|
|
102
150
|
end
|
|
103
151
|
|
|
104
152
|
collections.each do |collection_attr|
|
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.
|
|
4
|
+
version: 0.1.34
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Saurabh Asthana
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-04-
|
|
11
|
+
date: 2021-04-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rack
|
|
@@ -201,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
201
201
|
version: '0'
|
|
202
202
|
requirements: []
|
|
203
203
|
rubyforge_project:
|
|
204
|
-
rubygems_version: 2.7.6.
|
|
204
|
+
rubygems_version: 2.7.6.3
|
|
205
205
|
signing_key:
|
|
206
206
|
specification_version: 4
|
|
207
207
|
summary: Base classes for Mount Etna applications
|