eco-helpers 3.0.25 → 3.0.27
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/CHANGELOG.md +39 -1
- data/eco-helpers.gemspec +1 -1
- data/lib/eco/api/common/loaders/base.rb +13 -1
- data/lib/eco/api/common/loaders/case_base.rb +1 -1
- data/lib/eco/api/common/loaders/error_handler.rb +1 -1
- data/lib/eco/api/common/loaders/parser.rb +2 -2
- data/lib/eco/api/common/loaders/policy.rb +1 -1
- data/lib/eco/api/common/loaders/use_case.rb +1 -1
- data/lib/eco/api/common/people/default_parsers/archived_parser.rb +19 -0
- data/lib/eco/api/common/people/default_parsers/boolean_parser.rb +4 -4
- data/lib/eco/api/common/people/default_parsers/date_parser.rb +3 -3
- data/lib/eco/api/common/people/default_parsers/freemium_parser.rb +6 -6
- data/lib/eco/api/common/people/default_parsers/login_providers_parser.rb +3 -3
- data/lib/eco/api/common/people/default_parsers/multi_parser.rb +4 -4
- data/lib/eco/api/common/people/default_parsers/policy_groups_parser.rb +9 -6
- data/lib/eco/api/common/people/default_parsers/send_invites_parser.rb +6 -5
- data/lib/eco/api/common/people/default_parsers/xls_parser.rb +2 -2
- data/lib/eco/api/common/people/default_parsers.rb +1 -0
- data/lib/eco/api/common/people/entries.rb +16 -15
- data/lib/eco/api/common/people/person_entry.rb +53 -37
- data/lib/eco/api/common/people/person_parser.rb +8 -6
- data/lib/eco/api/common/session/logger/channels.rb +1 -1
- data/lib/eco/api/common/session/logger.rb +2 -2
- data/lib/eco/api/common/session/mailer/aws_provider.rb +3 -2
- data/lib/eco/api/common/session/mailer/provider_base.rb +6 -2
- data/lib/eco/api/common/session/mailer/sendgrid_provider.rb +9 -9
- data/lib/eco/api/common/session/mailer.rb +8 -3
- data/lib/eco/api/common/session/sftp.rb +2 -2
- data/lib/eco/api/common/version_patches/object.rb +2 -1
- data/lib/eco/api/custom/mailer.rb +1 -1
- data/lib/eco/api/error/handlers.rb +3 -3
- data/lib/eco/api/error.rb +17 -17
- data/lib/eco/api/microcases/people/apply_changes/set_account/account_excluded.rb +3 -11
- data/lib/eco/api/microcases/people/apply_changes/set_core/core_excluded.rb +4 -1
- data/lib/eco/api/microcases/people/manage/search.rb +3 -1
- data/lib/eco/api/organization/people.rb +1 -0
- data/lib/eco/api/policies.rb +2 -2
- data/lib/eco/api/session/batch/job.rb +2 -2
- data/lib/eco/api/session/batch/launcher.rb +4 -5
- data/lib/eco/api/session/batch/searcher.rb +4 -4
- data/lib/eco/api/session/config/api.rb +2 -2
- data/lib/eco/api/session/config/apis/enviro_spaces.rb +3 -3
- data/lib/eco/api/session/config/apis/space_helpers.rb +4 -4
- data/lib/eco/api/session/config/apis.rb +1 -1
- data/lib/eco/api/session/config/post_launch.rb +7 -4
- data/lib/eco/api/session/config/sftp.rb +1 -1
- data/lib/eco/api/session/config/tagtree.rb +1 -1
- data/lib/eco/api/session/config/workflow.rb +4 -4
- data/lib/eco/api/session/config.rb +25 -24
- data/lib/eco/api/session.rb +4 -4
- data/lib/eco/api/usecases/base_io/validations.rb +4 -3
- data/lib/eco/api/usecases/cli/option.rb +5 -2
- data/lib/eco/api/usecases/default/people/amend/clear_abilities_case.rb +2 -2
- data/lib/eco/api/usecases/default/people/amend/restore_db_case.rb +16 -9
- data/lib/eco/api/usecases/default/people/treat/analyse_people_case.rb +20 -20
- data/lib/eco/api/usecases/default.rb +5 -5
- data/lib/eco/api/usecases/default_cases/to_csv_case.rb +8 -8
- data/lib/eco/api/usecases/default_cases/upsert_case.rb +4 -4
- data/lib/eco/api/usecases/graphql/helpers/base.rb +1 -1
- data/lib/eco/api/usecases/graphql/helpers/location/base/tree_tracking.rb +5 -1
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/commandable.rb +2 -1
- data/lib/eco/api/usecases/graphql/helpers/location/command/result.rb +3 -3
- data/lib/eco/api/usecases/graphql/helpers/location/command.rb +3 -0
- data/lib/eco/api/usecases/graphql/samples/location/command/dsl.rb +2 -2
- data/lib/eco/api/usecases/graphql/samples/location/command/service/tree_update.rb +9 -3
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/inputable.rb +5 -4
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/parsing.rb +5 -2
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff.rb +3 -3
- data/lib/eco/api/usecases/graphql/utils/sftp.rb +1 -1
- data/lib/eco/api/usecases/lib/{file_pattern.rb → files/file_pattern.rb} +5 -1
- data/lib/eco/api/usecases/lib/{sftp.rb → files/sftp.rb} +27 -16
- data/lib/eco/api/usecases/lib/files.rb +7 -0
- data/lib/eco/api/usecases/lib.rb +1 -2
- data/lib/eco/api/usecases/ooze_cases/export_register_case.rb +5 -5
- data/lib/eco/api/usecases/ooze_samples/helpers/exportable_ooze.rb +14 -11
- data/lib/eco/api/usecases/ooze_samples/helpers_migration/copying.rb +14 -23
- data/lib/eco/api/usecases/ooze_samples/helpers_migration/typed_fields_pairing.rb +49 -27
- data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +9 -9
- data/lib/eco/api/usecases/ooze_samples/ooze_run_base_case.rb +1 -1
- data/lib/eco/api/usecases/ooze_samples/register_export_case.rb +25 -17
- data/lib/eco/api/usecases/ooze_samples/register_migration_case.rb +41 -24
- data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +16 -15
- data/lib/eco/api/usecases/samples/drivers/cli/sftp_cli.rb +15 -15
- data/lib/eco/api/usecases/samples/drivers/cli/url_pull_cli.rb +5 -5
- data/lib/eco/api/usecases/samples/drivers/sftp_sample.rb +2 -2
- data/lib/eco/api/usecases/use_case.rb +6 -6
- data/lib/eco/api/usecases/use_case_chain/chaining.rb +6 -6
- data/lib/eco/api/usecases/use_case_chain.rb +4 -4
- data/lib/eco/api/usecases/use_case_io.rb +2 -1
- data/lib/eco/api/usecases.rb +9 -9
- data/lib/eco/cli/config/options_set.rb +4 -4
- data/lib/eco/cli/config/use_cases.rb +3 -3
- data/lib/eco/cli/scripting/argument.rb +1 -1
- data/lib/eco/cli_default/input.rb +9 -9
- data/lib/eco/cli_default/options.rb +125 -100
- data/lib/eco/cli_default/people.rb +3 -3
- data/lib/eco/cli_default/usecases.rb +83 -83
- data/lib/eco/cli_default/workflow.rb +7 -7
- data/lib/eco/data/files/helpers.rb +3 -3
- data/lib/eco/data/fuzzy_match/result.rb +69 -26
- data/lib/eco/data/fuzzy_match/results.rb +10 -10
- data/lib/eco/data/fuzzy_match/score.rb +13 -8
- data/lib/eco/data/fuzzy_match.rb +65 -48
- data/lib/eco/data/locations/node_base/treeify.rb +13 -11
- data/lib/eco/data/mapper.rb +4 -4
- data/lib/eco/language/auxiliar_logger.rb +4 -4
- data/lib/eco/language/delegation/const_delegator.rb +64 -0
- data/lib/eco/language/delegation/const_lookup_hooks.rb +81 -0
- data/lib/eco/language/delegation/delegated_class.rb +84 -0
- data/lib/eco/language/delegation.rb +8 -0
- data/lib/eco/language/klass/when_inherited.rb +1 -0
- data/lib/eco/language/methods/delegate_missing.rb +1 -0
- data/lib/eco/language/models/class_helpers.rb +25 -23
- data/lib/eco/language/models/collection.rb +12 -2
- data/lib/eco/language.rb +1 -0
- data/lib/eco/version.rb +1 -1
- metadata +12 -6
@@ -69,7 +69,8 @@ class Eco::API::UseCases::OozeSamples
|
|
69
69
|
# @note
|
70
70
|
# - When used with `type: nil` it may pair fields of different type. There isn't refinement for this yet.
|
71
71
|
def with_src_dst_field_pair(src, dst, label: nil, label_dst: label, type: nil, src_excluded: [], dst_excluded: []) # rubocop:disable Metrics/AbcSize
|
72
|
-
msg
|
72
|
+
msg = "These helpers are to be included in class cases "
|
73
|
+
msg << "inheriting from Eco::API::UseCases::OozeSamples::RegisterUpdateCase"
|
73
74
|
raise msg unless respond_to?(:with_fields, true)
|
74
75
|
|
75
76
|
src_flds = with_fields(src, label: label, type: type)
|
@@ -82,7 +83,7 @@ class Eco::API::UseCases::OozeSamples
|
|
82
83
|
msg = "There isn't a '#{type}'"
|
83
84
|
dst_msg = dst_flds.empty?? "destination field named '#{label_dst}'" : nil
|
84
85
|
src_msg = src_flds.empty?? "source field named '#{label}'" : nil
|
85
|
-
msg << " #{[dst_msg, src_msg].join(
|
86
|
+
msg << " #{[dst_msg, src_msg].join(' or ')} (source: '#{src.id}')"
|
86
87
|
|
87
88
|
log(:warn) { msg }
|
88
89
|
return nil, nil
|
@@ -132,52 +133,42 @@ class Eco::API::UseCases::OozeSamples
|
|
132
133
|
def copy_field_content(src, dst) # rubocop:disable Metrics/AbcSize
|
133
134
|
type = src.type
|
134
135
|
case type
|
135
|
-
when
|
136
|
+
when 'select'
|
136
137
|
src.values.each {|val| dst.select(val)} # rubocop:disable Style/HashEachMethods
|
137
138
|
dst.other_desc = src.other_desc if src.other && src.other_desc && dst.other
|
138
|
-
when
|
139
|
+
when 'plain_text', 'date', 'number', 'gauge'
|
139
140
|
dst.value = src.value
|
140
|
-
when
|
141
|
+
when 'rich_text'
|
141
142
|
dst.content = src.content
|
142
|
-
when
|
143
|
+
when 'cross_reference'
|
143
144
|
src.reference_ids.each {|id| dst.add(id)}
|
144
|
-
when
|
145
|
+
when 'people'
|
145
146
|
dst.people_ids << src.people_ids.to_a
|
146
|
-
when
|
147
|
+
when 'geo'
|
147
148
|
src_coo = src.coordinates
|
148
149
|
dst_coo = dst.coordinates
|
149
150
|
dst_coo.lat, dst_coo.lon = src_coo.lat, src_coo.lon # rubocop:disable Style/ParallelAssignment
|
150
|
-
when
|
151
|
+
when 'file'
|
151
152
|
src.items.each do |src_item|
|
152
153
|
dst.add_file(src_item.file_container_id) do |dst_item|
|
153
154
|
dst_item.label = src_item.label
|
154
155
|
end
|
155
156
|
end
|
156
|
-
when
|
157
|
+
when 'image_gallery'
|
157
158
|
src.images.each do |src_image|
|
158
159
|
dst.add_image(src_image.upload_id) do |dst_image|
|
159
160
|
dst_image.caption = src_image.caption
|
160
161
|
end
|
161
162
|
end
|
162
|
-
when
|
163
|
+
when 'checklist'
|
163
164
|
src.items.each do |src_item|
|
164
165
|
dst.add_item(label: src_item.label) do |dst_item|
|
165
166
|
dst_item.checked = src_item.checked
|
166
167
|
end
|
167
168
|
end
|
168
|
-
when
|
169
|
+
when 'law', 'page_action', 'actions_list', 'signature'
|
169
170
|
"won't copy"
|
170
|
-
when
|
171
|
-
"won't copy"
|
172
|
-
when "actions_list"
|
173
|
-
"won't copy"
|
174
|
-
when "signature"
|
175
|
-
"can't copy"
|
176
|
-
when "tag_field"
|
177
|
-
"can't copy"
|
178
|
-
when "chart"
|
179
|
-
"won't copy"
|
180
|
-
when "frequency_rate_chart"
|
171
|
+
when 'tag_field', 'chart', 'frequency_rate_chart'
|
181
172
|
"won't copy"
|
182
173
|
end
|
183
174
|
end
|
@@ -12,7 +12,7 @@ class Eco::API::UseCases::OozeSamples
|
|
12
12
|
class TypedFieldsPairing
|
13
13
|
include Eco::API::UseCases::OozeSamples::Helpers::Shortcuts
|
14
14
|
|
15
|
-
EXCLUDED_TYPES = [
|
15
|
+
EXCLUDED_TYPES = %w[tag_field chart frequency_rate_chart].freeze
|
16
16
|
|
17
17
|
attr_reader :src, :dst
|
18
18
|
attr_reader :src_unpaired, :dst_unpaired
|
@@ -20,11 +20,12 @@ class Eco::API::UseCases::OozeSamples
|
|
20
20
|
|
21
21
|
def initialize(source, destination, src_excluded: nil, dst_excluded: nil,
|
22
22
|
exclude_ximport: false)
|
23
|
-
@src
|
24
|
-
@dst
|
25
|
-
@src_excluded
|
26
|
-
@dst_excluded
|
27
|
-
@exclude_ximport =
|
23
|
+
@src = source
|
24
|
+
@dst = destination
|
25
|
+
@src_excluded = src_excluded || []
|
26
|
+
@dst_excluded = dst_excluded || []
|
27
|
+
@exclude_ximport = exclude_ximport
|
28
|
+
|
28
29
|
reset!
|
29
30
|
process(exact: true)
|
30
31
|
process
|
@@ -37,28 +38,36 @@ class Eco::API::UseCases::OozeSamples
|
|
37
38
|
end
|
38
39
|
|
39
40
|
def report_src_unpaired(only_present: true, only_indexed: false)
|
40
|
-
return
|
41
|
-
|
41
|
+
return if src_unpaired.empty?
|
42
|
+
|
43
|
+
msg = "Source entry with unpaired fields (#{object_reference(src)}):\n"
|
44
|
+
|
42
45
|
src_filtered = src_unpaired.values.flatten.reject do |src_fld|
|
43
46
|
only_present && src_fld.empty?
|
44
47
|
end.reject do |src_fld|
|
45
48
|
only_indexed && src_fld.deindex
|
46
49
|
end
|
47
|
-
|
50
|
+
|
51
|
+
return if src_filtered.empty?
|
52
|
+
|
48
53
|
msg << src_filtered.map do |src_fld|
|
49
54
|
" * #{object_reference(src_fld)}"
|
50
55
|
end.join("\n")
|
51
56
|
end
|
52
57
|
|
53
58
|
def report_dst_unpaired(only_required: false, exclude_ximport: true)
|
54
|
-
return
|
55
|
-
|
59
|
+
return if dst_unpaired.empty?
|
60
|
+
|
61
|
+
msg = "Destination entry with unpaired fields (#{object_reference(src)}):\n"
|
62
|
+
|
56
63
|
dst_filtered = dst_unpaired.values.flatten.reject do |dst_fld|
|
57
64
|
only_required && !dst_fld.required
|
58
65
|
end.reject do |dst_fld|
|
59
66
|
exclude_ximport && ximport?(dst_fld)
|
60
67
|
end
|
61
|
-
|
68
|
+
|
69
|
+
return if dst_filtered.empty?
|
70
|
+
|
62
71
|
msg << dst_filtered.map do |dst_fld|
|
63
72
|
" * #{object_reference(dst_fld)}"
|
64
73
|
end.join("\n")
|
@@ -66,23 +75,27 @@ class Eco::API::UseCases::OozeSamples
|
|
66
75
|
|
67
76
|
def report_multi_pairs(only_present: true, only_indexed: false, dst_exclude_ximport: true)
|
68
77
|
return nil if src_dst_multi.empty?
|
69
|
-
|
70
|
-
msg
|
71
|
-
msg_flds =
|
78
|
+
''.tap do |msg|
|
79
|
+
msg << "Source fields in (#{object_reference(src)}) paired with multiple destination fields:\n"
|
80
|
+
msg_flds = ''
|
72
81
|
src_dst_multi.each do |type, pairs|
|
73
82
|
pairs.each do |(src_fld, dst_flds)|
|
74
83
|
next if (only_present && src_fld.empty?) || (only_indexed && src_fld.deindex)
|
84
|
+
|
75
85
|
dst_filtered = dst_flds.reject do |dst_fld|
|
76
86
|
dst_exclude_ximport && ximport?(dst_fld)
|
77
87
|
end
|
78
88
|
next if dst_filtered.empty?
|
89
|
+
|
79
90
|
msg_flds << " * #{object_reference(src_fld)}\n"
|
80
91
|
msg_flds << dst_filtered.map do |dst_fld|
|
81
92
|
" * #{object_reference(dst_fld)}"
|
82
93
|
end.compact.join("\n")
|
83
94
|
end
|
84
95
|
end
|
96
|
+
|
85
97
|
return nil if msg_flds.empty?
|
98
|
+
|
86
99
|
msg << msg_flds
|
87
100
|
end
|
88
101
|
end
|
@@ -91,8 +104,10 @@ class Eco::API::UseCases::OozeSamples
|
|
91
104
|
def resolve(*flds)
|
92
105
|
flds.each do |fld|
|
93
106
|
next if unpaired_delete(fld, src_unpaired)
|
107
|
+
|
94
108
|
unpaired_delete(fld, dst_unpaired)
|
95
109
|
end
|
110
|
+
|
96
111
|
multi_delete(*flds)
|
97
112
|
end
|
98
113
|
|
@@ -120,11 +135,13 @@ class Eco::API::UseCases::OozeSamples
|
|
120
135
|
def process(exact: false)
|
121
136
|
src_unpaired.each do |type, src_pend|
|
122
137
|
next unless (dst_pend = dst_unpaired[type]) && !dst_pend.empty?
|
138
|
+
|
123
139
|
src_pend.dup.each do |src_fld|
|
124
140
|
dst_candidates = dst_pend.select do |dst_fld|
|
125
141
|
str_eq?(src_fld.label, dst_fld.label, exact: exact)
|
126
142
|
end
|
127
143
|
next if dst_candidates.empty?
|
144
|
+
|
128
145
|
if dst_candidates.count == 1
|
129
146
|
pair_add(src_fld, dst_candidates.first)
|
130
147
|
else
|
@@ -134,14 +151,14 @@ class Eco::API::UseCases::OozeSamples
|
|
134
151
|
end
|
135
152
|
end
|
136
153
|
|
137
|
-
def str_eq?(
|
138
|
-
same_string?(
|
154
|
+
def str_eq?(str_1, str_2, exact: false)
|
155
|
+
same_string?(str_1, str_2, **str_eq_params, exact: exact)
|
139
156
|
end
|
140
157
|
|
141
158
|
def str_eq_params
|
142
159
|
{
|
143
|
-
exact:
|
144
|
-
mild:
|
160
|
+
exact: exact?,
|
161
|
+
mild: only_letters?,
|
145
162
|
ignore: false
|
146
163
|
}.tap do |params|
|
147
164
|
params.merge!(ignore: bracked_regex) if non_bracked?
|
@@ -158,13 +175,15 @@ class Eco::API::UseCases::OozeSamples
|
|
158
175
|
type = fld.type
|
159
176
|
return false unless unpaired.key?(type)
|
160
177
|
return false unless (flds = unpaired[type]).delete(fld)
|
178
|
+
|
161
179
|
unpaired.delete(type) if flds.empty?
|
162
180
|
true
|
163
181
|
end
|
164
182
|
|
165
183
|
def multi_add(type, src_fld, *dst_flds)
|
166
184
|
(src_dst_multi[type] ||= []) << (pair = [src_fld, dst_flds])
|
167
|
-
@src_multi[src_fld]
|
185
|
+
@src_multi[src_fld] = pair
|
186
|
+
|
168
187
|
dst_flds.each do |dst_fld|
|
169
188
|
(@dst_multi[dst_fld] ||= []) << pair
|
170
189
|
end
|
@@ -172,8 +191,9 @@ class Eco::API::UseCases::OozeSamples
|
|
172
191
|
|
173
192
|
def multi_delete(*flds)
|
174
193
|
flds.each do |fld|
|
175
|
-
next unless type_pairs = src_dst_multi[fld.type]
|
176
|
-
|
194
|
+
next unless (type_pairs = src_dst_multi[fld.type])
|
195
|
+
|
196
|
+
if (pairs = @dst_multi.delete(fld))
|
177
197
|
pairs.each do |pair|
|
178
198
|
src_fld = pair.first
|
179
199
|
dst_flds = pair.last
|
@@ -186,12 +206,14 @@ class Eco::API::UseCases::OozeSamples
|
|
186
206
|
elsif @src_multi.key?(fld)
|
187
207
|
pair = @src_multi.delete(fld)
|
188
208
|
type_pairs.delete(pair)
|
209
|
+
|
189
210
|
pair.last.each do |dst_fld|
|
190
211
|
pairs = @dst_multi[dst_fld]
|
191
212
|
pairs.delete(pair)
|
192
213
|
@dst_multi.delete(dst_fld) if pairs.empty?
|
193
214
|
end
|
194
215
|
end
|
216
|
+
|
195
217
|
src_dst_multi.delete(fld.type) if type_pairs.empty?
|
196
218
|
end
|
197
219
|
end
|
@@ -215,20 +237,20 @@ class Eco::API::UseCases::OozeSamples
|
|
215
237
|
end
|
216
238
|
|
217
239
|
def ximport?(fld)
|
218
|
-
fld && fld.tooltip.to_s.include?(
|
240
|
+
fld && fld.tooltip.to_s.include?('ximport')
|
219
241
|
end
|
220
242
|
|
221
243
|
def reset!
|
222
|
-
@src_unpaired
|
223
|
-
@dst_unpaired
|
244
|
+
@src_unpaired = by_type(src_components)
|
245
|
+
@dst_unpaired = by_type(dst_components)
|
224
246
|
@src_dst_pairs = []
|
225
247
|
reset_multi!
|
226
248
|
end
|
227
249
|
|
228
250
|
def reset_multi!
|
229
251
|
@src_dst_multi = {}
|
230
|
-
@src_multi
|
231
|
-
@dst_multi
|
252
|
+
@src_multi = {}
|
253
|
+
@dst_multi = {}
|
232
254
|
end
|
233
255
|
end
|
234
256
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# @attr_reader target [Ecoportal::API::V2::Page] current target ooze.
|
2
2
|
class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders::UseCase
|
3
|
-
name
|
3
|
+
name 'ooze-base'
|
4
4
|
type :other
|
5
5
|
|
6
6
|
include Eco::API::UseCases::OozeSamples::Helpers
|
@@ -8,7 +8,7 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
|
|
8
8
|
|
9
9
|
attr_reader :target
|
10
10
|
|
11
|
-
SAVE_PATCH =
|
11
|
+
SAVE_PATCH = 'ooze_patch_update.json'.freeze
|
12
12
|
DRY_COUNT = 5
|
13
13
|
|
14
14
|
def main(_session, options, _usecase)
|
@@ -37,7 +37,7 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
|
|
37
37
|
def create_page(page = nil, template_id: nil, retrieve: false)
|
38
38
|
template_id = template_id.id if template_id.is_a?(Ecoportal::API::V2::Page)
|
39
39
|
template_id ||= page.template_id if page.respond_to?(:template_id)
|
40
|
-
template_id ||= page[
|
40
|
+
template_id ||= page['template_id'] if page.is_a?(Hash)
|
41
41
|
page = new_page(template_id) unless page || !template_id
|
42
42
|
|
43
43
|
yield(page) if block_given?
|
@@ -190,8 +190,8 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
|
|
190
190
|
def new_target(object, warn_pending_changes: true)
|
191
191
|
if dirty?(target)
|
192
192
|
if warn_pending_changes
|
193
|
-
msg
|
194
|
-
msg
|
193
|
+
msg = "You you are switching to a new target #{object_reference(object)}"
|
194
|
+
msg << " after doing unsaved changes to #{object_reference(target)}"
|
195
195
|
log(:warn) { msg }
|
196
196
|
end
|
197
197
|
|
@@ -202,17 +202,17 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
|
|
202
202
|
end
|
203
203
|
|
204
204
|
def dirty?(object)
|
205
|
-
object && patch_doc(object)[
|
205
|
+
object && patch_doc(object)['page']
|
206
206
|
end
|
207
207
|
|
208
208
|
def backup_patch!(ooze = target)
|
209
|
-
unless (patch = (patch_doc(ooze) || {})[
|
209
|
+
unless (patch = (patch_doc(ooze) || {})['page'])
|
210
210
|
log(:info) { "No changes to update for #{object_reference(ooze)}." }
|
211
211
|
return
|
212
212
|
end
|
213
213
|
|
214
214
|
# store the request
|
215
|
-
File.open(SAVE_PATCH,
|
215
|
+
File.open(SAVE_PATCH, 'w') do |file|
|
216
216
|
#file << (patch_doc || {}).to_json
|
217
217
|
file << JSON.pretty_generate(patch || {})
|
218
218
|
end
|
@@ -222,7 +222,7 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
|
|
222
222
|
|
223
223
|
def display_patch(entry = target)
|
224
224
|
return if options.dig(:feedback, :only_stats)
|
225
|
-
return unless (patch = (patch_doc(entry) || {})[
|
225
|
+
return unless (patch = (patch_doc(entry) || {})['page'])
|
226
226
|
|
227
227
|
pp patch
|
228
228
|
end
|
@@ -6,7 +6,7 @@ class Eco::API::UseCases::OozeSamples::OozeRunBaseCase < Eco::API::UseCases::Ooz
|
|
6
6
|
SAVE_PATCH = 'ooze_patch_update.json'.freeze
|
7
7
|
|
8
8
|
def main(session, options, usecase)
|
9
|
-
super
|
9
|
+
super do
|
10
10
|
if method(:process_ooze).parameters.count.zero?
|
11
11
|
ooze # retrieve ooze
|
12
12
|
process_ooze
|
@@ -15,7 +15,7 @@ class Eco::API::UseCases::OozeSamples::RegisterExportCase < Eco::API::Common::Lo
|
|
15
15
|
|
16
16
|
include Eco::API::UseCases::OozeSamples::Helpers
|
17
17
|
|
18
|
-
name
|
18
|
+
name 'register-export-case'
|
19
19
|
type :other
|
20
20
|
|
21
21
|
attr_reader :session, :options, :usecase
|
@@ -58,29 +58,29 @@ class Eco::API::UseCases::OozeSamples::RegisterExportCase < Eco::API::Common::Lo
|
|
58
58
|
# @param ooze_id [String]
|
59
59
|
# @return [Ecoportal::API::V2::Page]
|
60
60
|
def build_full_ooze(ooze_id) # rubocop:disable Metrics/AbcSize
|
61
|
-
return
|
61
|
+
return unless (page = ooze(ooze_id))
|
62
62
|
return page unless page.is_a?(Ecoportal::API::V2::Pages::PageStage)
|
63
63
|
|
64
64
|
pending_stage_ids = page.stages.ordered.map(&:id) - [page.current_stage_id]
|
65
65
|
state = page.state
|
66
66
|
secs_doc = page.sections.doc
|
67
67
|
flds_doc = page.components.doc
|
68
|
-
hsecs = secs_doc.each_with_object({}) {|sec, h| h[sec[
|
69
|
-
hflds = flds_doc.each_with_object({}) {|fld, h| h[fld[
|
68
|
+
hsecs = secs_doc.each_with_object({}) {|sec, h| h[sec['id']] = sec}
|
69
|
+
hflds = flds_doc.each_with_object({}) {|fld, h| h[fld['id']] = fld}
|
70
70
|
|
71
71
|
pending_stage_ids.each do |id|
|
72
72
|
next unless (other_stage = stage(id, ooze: page))
|
73
73
|
|
74
|
-
state =
|
74
|
+
state = 'inprogress' unless other_stage.state == 'complete'
|
75
75
|
other_stage.sections.doc.each do |sec_doc|
|
76
|
-
unless hsecs.key?(id = sec_doc[
|
76
|
+
unless hsecs.key?(id = sec_doc['id'])
|
77
77
|
hsecs[id] = sec_doc
|
78
78
|
secs_doc << sec_doc
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
82
|
other_stage.components.doc.each do |comp_doc|
|
83
|
-
unless hflds.key?(id = comp_doc[
|
83
|
+
unless hflds.key?(id = comp_doc['id'])
|
84
84
|
hflds[id] = comp_doc
|
85
85
|
flds_doc << comp_doc
|
86
86
|
end
|
@@ -93,21 +93,27 @@ class Eco::API::UseCases::OozeSamples::RegisterExportCase < Eco::API::Common::Lo
|
|
93
93
|
end
|
94
94
|
|
95
95
|
def batched_search_results
|
96
|
-
|
96
|
+
msg = "Missing block. It yields in slices of #{self.class.batch_size} results"
|
97
|
+
raise msg unless block_given?
|
98
|
+
|
97
99
|
results_preview
|
98
100
|
results = []
|
101
|
+
|
99
102
|
apiv2.registers.search(register_id, search_options) do |page_result|
|
100
103
|
results << page_result
|
104
|
+
|
101
105
|
if results.length >= self.class.batch_size
|
102
106
|
yield(results)
|
103
107
|
results = []
|
104
108
|
end
|
105
109
|
end
|
110
|
+
|
106
111
|
yield(results) unless results.empty?
|
107
112
|
end
|
108
113
|
|
109
114
|
def ooze(ooze_id = nil, stage_id: nil)
|
110
115
|
return target unless ooze_id
|
116
|
+
|
111
117
|
apiv2.pages.get(ooze_id, stage_id: stage_id).tap do |ooze|
|
112
118
|
if ooze
|
113
119
|
new_target(ooze)
|
@@ -143,21 +149,22 @@ class Eco::API::UseCases::OozeSamples::RegisterExportCase < Eco::API::Common::Lo
|
|
143
149
|
end
|
144
150
|
|
145
151
|
def default_proceed
|
146
|
-
|
152
|
+
'Y'
|
147
153
|
end
|
148
154
|
|
149
155
|
def results_preview
|
150
156
|
apiv2.registers.search(register_id, search_options.merge(only_first: true)).tap do |search_results|
|
151
157
|
str_results = "Total target entries: #{search_results.total} (out of #{search_results.total_before_filtering})"
|
152
158
|
session.prompt_user(
|
153
|
-
|
159
|
+
'Do you want to proceed (y/N):',
|
154
160
|
explanation: str_results,
|
155
161
|
default: default_proceed,
|
156
162
|
timeout: 10
|
157
163
|
) do |res|
|
158
|
-
next if res.upcase.start_with?(
|
159
|
-
|
160
|
-
|
164
|
+
next if res.upcase.start_with?('Y')
|
165
|
+
|
166
|
+
puts '...'
|
167
|
+
log(:info) { 'Aborting script...' }
|
161
168
|
exit(0)
|
162
169
|
end
|
163
170
|
end
|
@@ -165,20 +172,21 @@ class Eco::API::UseCases::OozeSamples::RegisterExportCase < Eco::API::Common::Lo
|
|
165
172
|
|
166
173
|
def search_options
|
167
174
|
@search_options ||= {}.tap do |opts|
|
168
|
-
opts.merge!(sort:
|
169
|
-
opts.merge!(dir:
|
175
|
+
opts.merge!(sort: 'created_at')
|
176
|
+
opts.merge!(dir: 'asc')
|
170
177
|
opts.merge!(query: conf_search) if conf_search
|
171
178
|
opts.merge!(filters: conf_filters)
|
172
179
|
end
|
173
180
|
end
|
174
181
|
|
175
182
|
def conf_filters
|
176
|
-
return filters if respond_to?(:filters)
|
183
|
+
return filters if respond_to?(:filters, true)
|
184
|
+
|
177
185
|
[]
|
178
186
|
end
|
179
187
|
|
180
188
|
def conf_search
|
181
|
-
search if respond_to?(:search)
|
189
|
+
search if respond_to?(:search, true)
|
182
190
|
end
|
183
191
|
|
184
192
|
def register_id
|
@@ -47,9 +47,9 @@ class Eco::API::UseCases::OozeSamples::RegisterMigrationCase < Eco::API::UseCase
|
|
47
47
|
@csv = []
|
48
48
|
super(session, options, usecase, &block)
|
49
49
|
else
|
50
|
-
CSV.open(out_csv_filename,
|
50
|
+
CSV.open(out_csv_filename, 'w') do |csv|
|
51
51
|
@csv = csv
|
52
|
-
csv << [
|
52
|
+
csv << %w[src_page_id dst_page_id]
|
53
53
|
super(session, options, usecase, &block)
|
54
54
|
end
|
55
55
|
log(:info) { "File '#{out_csv_filename}' has been created." }
|
@@ -64,11 +64,11 @@ class Eco::API::UseCases::OozeSamples::RegisterMigrationCase < Eco::API::UseCase
|
|
64
64
|
# # More custom logics
|
65
65
|
# end
|
66
66
|
|
67
|
-
def process_ooze
|
67
|
+
def process_ooze # rubocop:disable Metrics/AbcSize
|
68
68
|
with_target_stage(self.class::SOURCE_STAGE) do |source|
|
69
69
|
draft_reference = object_reference(source)
|
70
70
|
creating_new_page(draft_reference, template_id: elf.class::TEMPLATE_ID) do |draft|
|
71
|
-
draft.base_tags << [
|
71
|
+
draft.base_tags << %w[IMPORTED MIGRATED]
|
72
72
|
|
73
73
|
pairing_tracking = copy_pairings(source, draft)
|
74
74
|
|
@@ -78,17 +78,24 @@ class Eco::API::UseCases::OozeSamples::RegisterMigrationCase < Eco::API::UseCase
|
|
78
78
|
yield(draft, source, fields_tracker: pairing_tracking)
|
79
79
|
end
|
80
80
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
81
|
+
msg = pairing_tracking.report_src_unpaired(
|
82
|
+
only_present: !self.class::REPORT_SRC_EMTPY,
|
83
|
+
only_indexed: !self.class::REPORT_SRC_DEINDEX
|
84
|
+
)
|
85
|
+
log(:warn) { msg } if msg
|
86
|
+
|
87
|
+
msg = pairing_tracking.report_multi_pairs(
|
88
|
+
only_present: !self.class::REPORT_SRC_EMTPY,
|
89
|
+
only_indexed: !self.class::REPORT_SRC_DEINDEX,
|
90
|
+
dst_exclude_ximport: !self.class::REPORT_DST_XIMPORT
|
91
|
+
)
|
92
|
+
log(:warn) { msg } if msg
|
93
|
+
|
94
|
+
msg = pairing_tracking.report_dst_unpaired(
|
95
|
+
only_required: false,
|
96
|
+
exclude_ximport: !self.class::REPORT_DST_XIMPORT
|
97
|
+
)
|
98
|
+
log(:warn) { msg } if msg
|
92
99
|
end
|
93
100
|
end
|
94
101
|
end
|
@@ -101,8 +108,18 @@ class Eco::API::UseCases::OozeSamples::RegisterMigrationCase < Eco::API::UseCase
|
|
101
108
|
src_excluded: excluded_fields(src),
|
102
109
|
dst_excluded: excluded_fields(dst)
|
103
110
|
}
|
104
|
-
copy_generic_paired_fields(
|
105
|
-
|
111
|
+
copy_generic_paired_fields(
|
112
|
+
src,
|
113
|
+
dst,
|
114
|
+
**params.merge(exclude_ximport: self.class::EXCLUDE_XIMPORT),
|
115
|
+
&after_copy
|
116
|
+
).tap do |pairs_track|
|
117
|
+
copy_mapped_fields(
|
118
|
+
src,
|
119
|
+
dst,
|
120
|
+
**params.merge(fields_tracker: pairs_track),
|
121
|
+
&after_copy
|
122
|
+
)
|
106
123
|
end
|
107
124
|
end
|
108
125
|
|
@@ -110,7 +127,8 @@ class Eco::API::UseCases::OozeSamples::RegisterMigrationCase < Eco::API::UseCase
|
|
110
127
|
return [] unless respond_to?(:excluded_field_hooks, true)
|
111
128
|
excluded_field_hooks.each_with_object([]) do |(type, hooks), excluded|
|
112
129
|
hooks.each do |hook|
|
113
|
-
type =
|
130
|
+
type = nil if type == 'all'
|
131
|
+
|
114
132
|
excluded.push(*with_fields(entry, label: to_regex(hook), type: type))
|
115
133
|
end
|
116
134
|
end
|
@@ -125,7 +143,8 @@ class Eco::API::UseCases::OozeSamples::RegisterMigrationCase < Eco::API::UseCase
|
|
125
143
|
def copy_mapped_fields(src, dst, **kargs, &after_copy)
|
126
144
|
return [] unless field_maps?
|
127
145
|
field_maps.each do |type, field_hooks|
|
128
|
-
type =
|
146
|
+
type = nil if type == 'all'
|
147
|
+
|
129
148
|
field_hooks.each do |hook_name|
|
130
149
|
copy_hooked_fields(src, dst, hook: hook_name, type: type, **kargs, &after_copy)
|
131
150
|
end
|
@@ -137,17 +156,15 @@ class Eco::API::UseCases::OozeSamples::RegisterMigrationCase < Eco::API::UseCase
|
|
137
156
|
end
|
138
157
|
|
139
158
|
def callback(sym)
|
140
|
-
if callback?(sym)
|
141
|
-
method(callback_name(sym))
|
142
|
-
end
|
159
|
+
method(callback_name(sym)) if callback?(sym)
|
143
160
|
end
|
144
161
|
|
145
162
|
def callback_name(sym)
|
146
|
-
"#{sym}_callback"
|
163
|
+
:"#{sym}_callback"
|
147
164
|
end
|
148
165
|
|
149
166
|
def with_target_stage(name)
|
150
|
-
if stg = target_stage(name)
|
167
|
+
if (stg = target_stage(name))
|
151
168
|
yield(stg)
|
152
169
|
else
|
153
170
|
log(:warn) { "Entry '#{target.id}' does not have stage '#{name}'" }
|