eco-helpers 2.1.5 → 2.1.7
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 +19 -3
- data/lib/eco/api/usecases/ooze_samples/helpers/shortcuts.rb +1 -1
- data/lib/eco/api/usecases/ooze_samples/helpers_migration/copying.rb +43 -17
- data/lib/eco/api/usecases/ooze_samples/helpers_migration/typed_fields_pairing.rb +1 -1
- data/lib/eco/api/usecases/ooze_samples/register_migration_case.rb +24 -4
- data/lib/eco/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57558123bd83d606799604772ef717673f58bd089efc90458116a3126b1742f4
|
4
|
+
data.tar.gz: 99ec5e1bf52f4cd3ce3bbab5da60c64bfb42aa7742dfbe85897b40bfd6c76471
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d5bbe4a67ec3b9f18025877ecc3ce8735a8e816be686a17deee58be2e9f1d1c35b54b73a004440210905b113230224c8ce9f2b225746e7bf7c276b274f67b5e
|
7
|
+
data.tar.gz: 3d492d4ead671bc288621135e197ee3ce42ed40a10b73546ca7b8f3c3b9d137c2048105beda464d2d7b0d443dde510f3c86edac0bdb68f5262ae434f063864f8
|
data/CHANGELOG.md
CHANGED
@@ -1,13 +1,29 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
-
## [2.1.
|
4
|
+
## [2.1.8] - 2022-11-xx
|
5
5
|
|
6
6
|
### Added
|
7
7
|
### Changed
|
8
8
|
### Fixed
|
9
9
|
|
10
|
-
## [2.1.
|
10
|
+
## [2.1.7] - 2022-11-17
|
11
|
+
|
12
|
+
### Added
|
13
|
+
- `Eco::API::UseCases::OozeSamples::RegisterMigrationCase` method `excluded_field_hooks`
|
14
|
+
- This enables the ability to prevent fields from being paired/copied/written on
|
15
|
+
|
16
|
+
### Changed
|
17
|
+
- **refactored** `#with_src_dst_field_pair` helper
|
18
|
+
- from `Eco::API::UseCases::OozeSamples::HelpersMigration::Copying`
|
19
|
+
|
20
|
+
## [2.1.6] - 2022-11-17
|
21
|
+
|
22
|
+
### Fixed
|
23
|
+
- `Eco::API::UseCases::OozeSamples::Helpers::Shortcuts#to_i` (missing param on method)
|
24
|
+
- `Eco::API::UseCases::OozeSamples::HelpersMigration::TypedFieldsPairing#multi_delete` typo
|
25
|
+
|
26
|
+
## [2.1.5] - 2022-11-17
|
11
27
|
|
12
28
|
### Added
|
13
29
|
- `Eco::API::UseCases::OozeSamples::RegisterUpdateCase` added creation count
|
@@ -16,7 +32,7 @@ All notable changes to this project will be documented in this file.
|
|
16
32
|
- `with_rescue` that prompts user to continue
|
17
33
|
- this is for usage in child classes
|
18
34
|
- new use case and helpers thereof `Eco::API::UseCases::OozeSamples::RegisterMigrationCase`
|
19
|
-
|
35
|
+
|
20
36
|
### Changed
|
21
37
|
- upgraded `ecoportal-api-v2` **gem**
|
22
38
|
- **refactored** `Eco::API::UseCases::OozeSamples::Helpers::Shortcuts#same_string?`
|
@@ -9,8 +9,8 @@ class Eco::API::UseCases::OozeSamples
|
|
9
9
|
session.logger
|
10
10
|
end
|
11
11
|
|
12
|
-
def copy_generic_paired_fields(src, dst, exclude_ximport: false)
|
13
|
-
HelpersMigration::TypedFieldsPairing.new(src, dst, exclude_ximport: false).tap do |pairing|
|
12
|
+
def copy_generic_paired_fields(src, dst, src_excluded: [], dst_excluded: [], exclude_ximport: false)
|
13
|
+
HelpersMigration::TypedFieldsPairing.new(src, dst, src_excluded: src_excluded, dst_excluded: dst_excluded, exclude_ximport: false).tap do |pairing|
|
14
14
|
pairing.each_pair do |src_fld, dst_fld|
|
15
15
|
copy_field_content(src_fld, dst_fld)
|
16
16
|
yield(src_fld, dst_fld, pairing) if block_given?
|
@@ -18,11 +18,11 @@ class Eco::API::UseCases::OozeSamples
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
def copy_hooked_fields(src, dst, hook:, type:, fields_tracker: nil)
|
21
|
+
def copy_hooked_fields(src, dst, hook:, type:, fields_tracker: nil, src_excluded: [], dst_excluded: [])
|
22
22
|
case hook
|
23
23
|
when String
|
24
|
-
|
25
|
-
copy_field_content(src_fld, dst_fld
|
24
|
+
with_src_dst_field_pair(src, dst, label: to_regex(hook), type: type, src_excluded: src_excluded, dst_excluded: dst_excluded) do |src_fld, dst_fld|
|
25
|
+
copy_field_content(src_fld, dst_fld).tap do |result|
|
26
26
|
fields_tracker.resolve(src_fld, dst_fld) if fields_tracker
|
27
27
|
yield(src_fld, dst_fld, fields_tracker) if block_given?
|
28
28
|
end
|
@@ -30,8 +30,8 @@ class Eco::API::UseCases::OozeSamples
|
|
30
30
|
when Hash
|
31
31
|
hook.each do |hook_src, hook_dst|
|
32
32
|
src_lab, dst_lab = to_regex(hook_src), to_regex(hook_dst)
|
33
|
-
|
34
|
-
copy_field_content(src_fld, dst_fld
|
33
|
+
with_src_dst_field_pair(src, dst, label: src_lab, label_dst: dst_lab, type: type, src_excluded: src_excluded, dst_excluded: dst_excluded) do |src_fld, dst_fld|
|
34
|
+
copy_field_content(src_fld, dst_fld).tap do |result|
|
35
35
|
fields_tracker.resolve(src_fld, dst_fld) if fields_tracker
|
36
36
|
yield(src_fld, dst_fld, fields_tracker) if block_given?
|
37
37
|
end
|
@@ -44,33 +44,59 @@ class Eco::API::UseCases::OozeSamples
|
|
44
44
|
/^#{str}$/i
|
45
45
|
end
|
46
46
|
|
47
|
-
|
47
|
+
# @note
|
48
|
+
# - When used with `type: nil` it may pair fields of different type. There isn't refinement for this yet.
|
49
|
+
def with_src_dst_field_pair(src, dst, label: nil, label_dst: label, type: nil, src_excluded: [], dst_excluded: [])
|
48
50
|
unless respond_to?(:with_fields, true)
|
49
51
|
raise "These helpers are to be included in class cases inheriting from Eco::API::UseCases::OozeSamples::RegisterUpdateCase"
|
50
52
|
end
|
51
53
|
src_flds = with_fields(src, label: label, type: type)
|
52
54
|
dst_flds = with_fields(dst, label: label_dst, type: type)
|
55
|
+
src_fld, dst_fld = src_flds.first, dst_flds.first
|
56
|
+
|
57
|
+
# Not found
|
58
|
+
if dst_flds.empty? || src_flds.empty?
|
59
|
+
msg = "There isn't a '#{type}'"
|
60
|
+
dst_msg = dst_flds.empty?? "destination field named '#{label_dst}'" : nil
|
61
|
+
src_msg = src_flds.empty?? "source field named '#{label}'" : nil
|
62
|
+
msg << " #{[dst_msg, src_msg].join(" or ")} (source: '#{src.id}')"
|
63
|
+
logger.warn(msg)
|
64
|
+
return nil, nil
|
65
|
+
end
|
66
|
+
|
67
|
+
# Fields exclusion
|
68
|
+
dst_flds -= dst_excluded unless dst_excluded.empty?
|
69
|
+
src_flds -= src_excluded unless src_excluded.empty?
|
70
|
+
src_fld, dst_fld = src_flds.first, dst_flds.first
|
71
|
+
return src_fld, dst_fld if dst_flds.empty? || src_flds.empty?
|
53
72
|
|
54
73
|
if dst_flds.count > 1
|
55
74
|
logger.warn("There are #{dst_flds.count} destination '#{type}' fields named '#{label_dst}' (source: '#{src.id}'). Using first...")
|
56
|
-
elsif dst_flds.empty?
|
57
|
-
logger.warn("There isn't a destination '#{type}' field named '#{label_dst}' (source: '#{src.id}')")
|
58
|
-
return nil, nil
|
59
75
|
end
|
60
76
|
|
61
77
|
if src_flds.count > 1
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
78
|
+
msg = "There are #{src_flds.count} source '#{type}' fields named '#{label}' (source: '#{src.id}'). "
|
79
|
+
src_content = src_flds.reject(&:empty?)
|
80
|
+
if src_content.empty?
|
81
|
+
msg << "None with content. Using first..."
|
82
|
+
else
|
83
|
+
src_fld = src_content.first
|
84
|
+
if src_content.count == 1
|
85
|
+
msg << "Using the only one with content (idx: #{src_flds.index(src_fld)})..."
|
86
|
+
else
|
87
|
+
msg << "#{src_content.count} have content. Using first..."
|
88
|
+
end
|
89
|
+
end
|
90
|
+
logger.warn(msg)
|
66
91
|
end
|
67
92
|
|
68
|
-
[
|
93
|
+
[src_fld, dst_fld].tap do |(src_fld, dst_fld)|
|
69
94
|
yield(src_fld, dst_fld) if block_given?
|
70
95
|
end
|
71
96
|
end
|
72
97
|
|
73
|
-
def copy_field_content(src, dst
|
98
|
+
def copy_field_content(src, dst)
|
99
|
+
type = src.type
|
74
100
|
case type
|
75
101
|
when "select"
|
76
102
|
src.values.each {|val| dst.select(val)}
|
@@ -7,12 +7,17 @@
|
|
7
7
|
# 1. field label name (String or RegExp body/source),
|
8
8
|
# 2. or an object with key-value being source-destination label names (also supports RegExp body/source)
|
9
9
|
# - Example: {"select": ["severity of .*:", {"type of event:" => "type of incident:"}]}
|
10
|
+
# - "all" as type will target all type of fields.
|
11
|
+
# - Caution with this! Copying between fields of different types is not yet supported.
|
10
12
|
# - You may either
|
11
13
|
# 1. define the `process_ooze` method calling super with a block: super.do ||
|
12
14
|
# 2. of define the function `custom_processing(draft, source, fields_tracker: nil)`
|
13
15
|
# - You can define a callback function, `paired_fields_post_callback(src_fld, dst_fld, pairing_tracking = nil)`
|
14
16
|
# - It will be called after copying by using any of the pairing methods, and allows to introduce modifications
|
15
17
|
# such as selection option mappings
|
18
|
+
# - You may define a method called `excluded_field_hooks` with same syntax as the json pairing file
|
19
|
+
# - This will exclude as source and destination targets any fields matching those patterns.
|
20
|
+
# - This is specially useful to discard rich text field guidelines (i.e. `{"rich_text" => [".*guideline:"]}`)
|
16
21
|
# This case expects `options[:source][:register_id]`
|
17
22
|
class Eco::API::UseCases::OozeSamples::RegisterMigrationCase < Eco::API::UseCases::OozeSamples::RegisterUpdateCase
|
18
23
|
name "register-migration-case"
|
@@ -101,8 +106,22 @@ class Eco::API::UseCases::OozeSamples::RegisterMigrationCase < Eco::API::UseCase
|
|
101
106
|
|
102
107
|
def copy_pairings(src, dst)
|
103
108
|
after_copy = callback(:paired_fields_post)
|
104
|
-
|
105
|
-
|
109
|
+
params = {
|
110
|
+
src_excluded: excluded_fields(src),
|
111
|
+
dst_excluded: excluded_fields(dst)
|
112
|
+
}
|
113
|
+
copy_generic_paired_fields(src, dst, **params.merge(exclude_ximport: self.class::EXCLUDE_XIMPORT), &after_copy).tap do |pairing_tracking|
|
114
|
+
copy_mapped_fields(src, dst, **params.merge(fields_tracker: pairing_tracking), &after_copy)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def excluded_fields(entry)
|
119
|
+
return [] unless respond_to?(:excluded_field_hooks, true)
|
120
|
+
excluded_field_hooks.each_with_object([]) do |(type, hooks), excluded|
|
121
|
+
hooks.each do |hook|
|
122
|
+
type = (type == "all")? nil : type
|
123
|
+
excluded.push(*with_fields(entry, label: to_regex(hook), type: type))
|
124
|
+
end
|
106
125
|
end
|
107
126
|
end
|
108
127
|
|
@@ -112,11 +131,12 @@ class Eco::API::UseCases::OozeSamples::RegisterMigrationCase < Eco::API::UseCase
|
|
112
131
|
raise msg
|
113
132
|
end
|
114
133
|
|
115
|
-
def copy_mapped_fields(src, dst,
|
134
|
+
def copy_mapped_fields(src, dst, **kargs, &after_copy)
|
116
135
|
return [] unless field_maps?
|
117
136
|
field_maps.each do |type, field_hooks|
|
137
|
+
type = (type == "all")? nil : type
|
118
138
|
field_hooks.each do |hook_name|
|
119
|
-
copy_hooked_fields(src, dst, hook: hook_name, type: type,
|
139
|
+
copy_hooked_fields(src, dst, hook: hook_name, type: type, **kargs, &after_copy)
|
120
140
|
end
|
121
141
|
end
|
122
142
|
end
|
data/lib/eco/version.rb
CHANGED