eco-helpers 3.0.4 → 3.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/CHANGELOG.md +44 -4
- data/eco-helpers.gemspec +1 -1
- data/lib/eco/api/common/class_helpers.rb +24 -23
- data/lib/eco/api/common/class_meta_basics.rb +0 -2
- data/lib/eco/api/common/loaders/use_case.rb +1 -0
- data/lib/eco/api/common/people/entry_factory.rb +6 -4
- data/lib/eco/api/common/people/person_entry.rb +4 -6
- data/lib/eco/api/common/people/person_entry_attribute_mapper.rb +25 -12
- data/lib/eco/api/common/people/person_parser.rb +8 -0
- data/lib/eco/api/common/session/base_session.rb +1 -1
- data/lib/eco/api/common/session/environment.rb +7 -0
- data/lib/eco/api/common/session/file_manager.rb +15 -8
- data/lib/eco/api/common/session/logger/cache.rb +14 -10
- data/lib/eco/api/common/session/logger/log.rb +8 -7
- data/lib/eco/api/common/session/mailer.rb +22 -13
- data/lib/eco/api/common/session/s3_uploader.rb +29 -20
- data/lib/eco/api/microcases/people_search.rb +1 -1
- data/lib/eco/api/organization/login_providers.rb +11 -4
- data/lib/eco/api/organization/node_classifications.rb +3 -0
- data/lib/eco/api/organization/presets_factory.rb +37 -31
- data/lib/eco/api/organization/tag_tree.rb +14 -5
- data/lib/eco/api/policies/default_policies/99_user_access_policy.rb +28 -18
- data/lib/eco/api/session/batch/errors.rb +38 -20
- data/lib/eco/api/session/batch/job.rb +252 -135
- data/lib/eco/api/session/batch/status.rb +55 -36
- data/lib/eco/api/session/batch.rb +2 -2
- data/lib/eco/api/session/config/base_config.rb +12 -11
- data/lib/eco/api/session/config/tagtree.rb +10 -14
- data/lib/eco/api/session/config/workflow.rb +15 -3
- data/lib/eco/api/session/config.rb +19 -26
- data/lib/eco/api/session.rb +13 -4
- data/lib/eco/api/usecases/cli.rb +4 -0
- data/lib/eco/api/usecases/default/locations/cli/codes_to_tags_cli.rb +18 -0
- data/lib/eco/api/usecases/default/locations/cli/csv_to_tree_cli.rb +12 -0
- data/lib/eco/api/usecases/default/locations/cli/tagtree_paths_cli.rb +12 -0
- data/lib/eco/api/usecases/default/locations/codes_to_tags_case.rb +32 -13
- data/lib/eco/api/usecases/default/locations/csv_to_tree_case.rb +15 -5
- data/lib/eco/api/usecases/default/locations/tagtree_extract_case.rb +6 -0
- data/lib/eco/api/usecases/default/locations/tagtree_paths_case.rb +51 -0
- data/lib/eco/api/usecases/default/locations.rb +1 -1
- data/lib/eco/api/usecases/default/people/amend/cli/reinvite_sync_cli.rb +8 -0
- data/lib/eco/api/usecases/default/people/amend/cli/reinvite_trans_cli.rb +11 -0
- data/lib/eco/api/usecases/default/people/amend/cli/restore_db_cli.rb +26 -0
- data/lib/eco/api/usecases/default/people/amend/reinvite_sync_case.rb +2 -0
- data/lib/eco/api/usecases/default/people/amend/reinvite_trans_case.rb +2 -0
- data/lib/eco/api/usecases/default/people/amend/restore_db_case.rb +3 -0
- data/lib/eco/api/usecases/default/people/treat/analyse_people_case.rb +15 -5
- data/lib/eco/api/usecases/default/people/treat/cli/analyse_people_cli.rb +66 -0
- data/lib/eco/api/usecases/default/people/treat/cli/org_data_convert_cli.rb +35 -0
- data/lib/eco/api/usecases/default/people/treat/cli/supers_cyclic_identify_cli.rb +15 -0
- data/lib/eco/api/usecases/default/people/treat/cli/supers_hierachy_cli.rb +15 -0
- data/lib/eco/api/usecases/default/people/treat/org_data_convert_case.rb +11 -5
- data/lib/eco/api/usecases/default/people/treat/supers_cyclic_identify_case.rb +28 -7
- data/lib/eco/api/usecases/default/people/treat/supers_hierarchy_case.rb +32 -9
- data/lib/eco/api/usecases/default/people/utils/set_default_tag_case.rb +2 -1
- data/lib/eco/api/usecases/default_cases/to_csv_case.rb +2 -2
- data/lib/eco/api/usecases/graphql/helpers/location/base/classifications_parser.rb +5 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/commandable.rb +2 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/diff_sortable.rb +2 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/result.rb +2 -1
- data/lib/eco/api/usecases/graphql/helpers/location/command/results.rb +3 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command.rb +1 -0
- data/lib/eco/api/usecases/graphql/helpers/location/tags_remap.rb +3 -0
- data/lib/eco/api/usecases/graphql/samples/location/command/service/tree_update.rb +2 -0
- data/lib/eco/api/usecases/graphql/samples/location/command/track_changed_ids.rb +1 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/parsing/classifications.rb +2 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff.rb +6 -2
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/parser.rb +6 -2
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb +2 -0
- data/lib/eco/api/usecases/ooze_cases/export_register_case.rb +1 -0
- data/lib/eco/api/usecases/ooze_samples/helpers_migration/copying.rb +66 -29
- data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +25 -3
- data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +10 -0
- data/lib/eco/api/usecases/use_case.rb +3 -1
- data/lib/eco/cli/config/use_cases.rb +4 -0
- data/lib/eco/cli/scripting/args_helpers.rb +3 -2
- data/lib/eco/cli/scripting/argument.rb +2 -2
- data/lib/eco/cli_default/input.rb +49 -45
- data/lib/eco/cli_default/input_filters.rb +32 -17
- data/lib/eco/cli_default/options.rb +8 -4
- data/lib/eco/cli_default/people.rb +1 -1
- data/lib/eco/cli_default/people_filters.rb +32 -24
- data/lib/eco/cli_default/usecases.rb +8 -121
- data/lib/eco/cli_default/workflow.rb +6 -4
- data/lib/eco/csv/split.rb +2 -0
- data/lib/eco/csv/table.rb +13 -0
- data/lib/eco/data/files/encoding.rb +15 -8
- data/lib/eco/data/files/helpers.rb +6 -2
- data/lib/eco/data/hashes/diff_result.rb +5 -0
- data/lib/eco/data/locations/node_diff/nodes_diff.rb +13 -0
- data/lib/eco/data/locations/node_diff.rb +4 -0
- data/lib/eco/data/locations/node_level.rb +6 -0
- data/lib/eco/language/auxiliar_logger.rb +2 -0
- data/lib/eco/version.rb +1 -1
- data/lib/eco-helpers.rb +1 -1
- metadata +15 -6
- data/lib/eco/api/usecases/default/locations/create_tag_paths_case.rb +0 -25
- data/lib/eco/api/usecases/default/people/amend/reinvite_trans_cli.rb +0 -4
@@ -1,3 +1,4 @@
|
|
1
|
+
# rubocop:disable Naming/MethodParameterName
|
1
2
|
module Eco
|
2
3
|
module API
|
3
4
|
class Session
|
@@ -6,18 +7,15 @@ module Eco
|
|
6
7
|
# 1. what has happened during the execution of a `Session::Batch` (i.e. errors)
|
7
8
|
# 2. be able to build a summary of what happened
|
8
9
|
# 3. gather the people that was returned as a result of the `batch` (for `get` batch type)
|
9
|
-
# @attr_reader source_queue [Array<Hash>, Array<Ecoportal::API::V1::Person>,
|
10
|
+
# @attr_reader source_queue [Array<Hash>, Array<Ecoportal::API::V1::Person>,
|
11
|
+
# Array<Ecoportal::API::Internal::Person>]
|
10
12
|
# The queue as it was originally made (it could contain duplicates)
|
11
13
|
# @attr_reader queue [Array<Hash>, Array<Ecoportal::API::V1::Person>, Array<Ecoportal::API::Internal::Person>]
|
12
14
|
# `source_queue` with no repeated elements (**note**: observe that the elimination of duplicates could fail)
|
13
15
|
# @attr_reader mode [Symbol] the `mode` that the `batch` was run with
|
14
16
|
# @attr_reader root [Eco::API::Session::Job] the `job` that launched the `batch`
|
15
17
|
class Status < Eco::API::Common::Session::BaseSession
|
16
|
-
@modes = [
|
17
|
-
|
18
|
-
attr_reader :source_queue
|
19
|
-
attr_reader :queue, :method, :mode
|
20
|
-
attr_reader :root
|
18
|
+
@modes = %i[exact search]
|
21
19
|
|
22
20
|
class << self
|
23
21
|
attr_reader :modes
|
@@ -27,13 +25,25 @@ module Eco
|
|
27
25
|
end
|
28
26
|
end
|
29
27
|
|
30
|
-
|
31
|
-
|
28
|
+
attr_reader :source_queue
|
29
|
+
attr_reader :queue, :method, :mode
|
30
|
+
|
31
|
+
# Nativelly to this gem, a batch against the server is lauched by an Eco::API::Session::Job.
|
32
|
+
# When the batch returns the `BatchStatus`, the `Job` assigns itself as `root` of it.
|
33
|
+
# @param object [Eco::API::Session::Job]
|
34
|
+
attr_accessor :root
|
35
|
+
|
36
|
+
# @param e [Eco::API::Common::Session::Environment] requires a session environment,
|
37
|
+
# as any child of `Eco::API::Common::Session::BaseSession`
|
38
|
+
# @param queue [Array<Hash>, Array<Ecoportal::API::V1::Person>, Array<Ecoportal::API::Internal::Person>]
|
39
|
+
# the `source_queue`
|
32
40
|
# @param method [Symbol] the type of `batch operation`
|
33
41
|
# @param mode [Symbol] the mode of `batch operation`. It can be `:search` or `:exact`
|
34
|
-
def initialize(
|
35
|
-
super(
|
36
|
-
|
42
|
+
def initialize(ev, queue:, method:, mode: :exact)
|
43
|
+
super(ev)
|
44
|
+
|
45
|
+
msg = "In batch operations you must batch an Enumerable. Received: #{queue.class}"
|
46
|
+
fatal(msg) unless queue.is_a?(Enumerable)
|
37
47
|
|
38
48
|
self.mode = mode
|
39
49
|
@method = method
|
@@ -41,8 +51,12 @@ module Eco
|
|
41
51
|
|
42
52
|
que = queue.to_a
|
43
53
|
que = queue if queue.respond_to?(:uniq)
|
54
|
+
|
44
55
|
if que.length != que.uniq.length
|
45
|
-
|
56
|
+
log(:warn) {
|
57
|
+
"Please, review your entries-to-query builder, you have repeated entries"
|
58
|
+
}
|
59
|
+
|
46
60
|
queue = que.uniq
|
47
61
|
end
|
48
62
|
|
@@ -50,20 +64,16 @@ module Eco
|
|
50
64
|
@hash = @queue.each_with_index.map do |entry, i|
|
51
65
|
[entry, i]
|
52
66
|
end.to_h
|
67
|
+
|
53
68
|
@responses = []
|
54
69
|
@person_match = []
|
55
70
|
@people_match = Array.new(@queue.length, [])
|
56
71
|
end
|
57
72
|
|
58
|
-
# Nativelly to this gem, a batch against the server is lauched by an Eco::API::Session::Job.
|
59
|
-
# When the batch returns the `BatchStatus`, the `Job` assigns itself as `root` of it.
|
60
|
-
# @param object [Eco::API::Session::Job]
|
61
|
-
def root=(object)
|
62
|
-
@root = object
|
63
|
-
end
|
64
|
-
|
65
73
|
def mode=(value)
|
66
|
-
|
74
|
+
msg = "Invalid :mode '#{value}'. You must specify mode: as one of #{self.class.modes} "
|
75
|
+
fatal(msg) unless self.class.valid_mode?(value)
|
76
|
+
|
67
77
|
@mode = value
|
68
78
|
end
|
69
79
|
|
@@ -79,10 +89,12 @@ module Eco
|
|
79
89
|
end
|
80
90
|
|
81
91
|
# Get the assciated `reponse` of an input entry object `key`
|
82
|
-
# @param key [Integer, Hash, Ecoportal::API::V1::Person, Ecoportal::API::Internal::Person]
|
92
|
+
# @param key [Integer, Hash, Ecoportal::API::V1::Person, Ecoportal::API::Internal::Person]
|
93
|
+
# these are the **index options**:
|
83
94
|
# 1. `Integer`: index/position of the entry in the final `queue`
|
84
95
|
# 2. `Hash`: entry queries can be raw `Hash` objects
|
85
|
-
# 3. `Person` object: the most common case is to use the person
|
96
|
+
# 3. `Person` object: the most common case is to use the person
|
97
|
+
# wrapper classes of the `Ecoportal::API` namespace.
|
86
98
|
# @return [Ecoportal::API::Common::BatchResponse]
|
87
99
|
def [](key)
|
88
100
|
@responses[to_index(key)]
|
@@ -121,12 +133,13 @@ module Eco
|
|
121
133
|
# @return [Integer] the actual `index`
|
122
134
|
def valid_index(index: nil, entry: nil)
|
123
135
|
index ||= @hash[entry]
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
index
|
136
|
+
|
137
|
+
return index if index && index < @queue.length
|
138
|
+
|
139
|
+
msg = "You must provide either the index on the final 'queue' "
|
140
|
+
msg << "or the original entry object of the batch. "
|
141
|
+
msg << "Given, index=#{index.class}, entry:#{entry.class}"
|
142
|
+
fatal msg
|
130
143
|
end
|
131
144
|
|
132
145
|
# @!group Get-specific helpers
|
@@ -137,14 +150,14 @@ module Eco
|
|
137
150
|
# @see Eco::API::Session::Batch::Status#[] for `key` options
|
138
151
|
# @return [Ecoportal::API::V1::Person, Ecoportal::API::Internal::Person]
|
139
152
|
def person(key)
|
140
|
-
|
141
|
-
nil
|
153
|
+
self[key].result if success?(key)
|
142
154
|
end
|
143
155
|
|
144
156
|
# The _person_ we got from the Server wrapped to the `Person` object for the input entry object `key`
|
145
157
|
# @note
|
146
158
|
# - it only makes sense when the _batch method_ used was `get` with `q`
|
147
|
-
# - **found using a search criteria** (`mode` == `:search`), as opposite
|
159
|
+
# - **found using a search criteria** (`mode` == `:search`), as opposite
|
160
|
+
# to find the person directly by `external_id`
|
148
161
|
# @param key [Integer, Hash, Ecoportal::API::V1::Person, Ecoportal::API::Internal::Person]
|
149
162
|
# @see Eco::API::Session::Batch::Status#[] for `key` options
|
150
163
|
# @return [Ecoportal::API::V1::Person, Ecoportal::API::Internal::Person]
|
@@ -169,9 +182,12 @@ module Eco
|
|
169
182
|
# - while `:exact` mode will keep the order of found people as per order of final `queue`
|
170
183
|
# - `:search` mode will just gather the results (order won't match)
|
171
184
|
# @raise [Exception] when the `method` of the batch operation was other than `get`
|
172
|
-
# @return [Array<Ecoportal::API::V1::Person>, Array<Ecoportal::API::Internal::Person>]
|
185
|
+
# @return [Array<Ecoportal::API::V1::Person>, Array<Ecoportal::API::Internal::Person>]
|
186
|
+
# all the people that has been found.
|
173
187
|
def people
|
174
|
-
|
188
|
+
msg = "This batch wasn't a 'get'. Can't obtain people without 'get' method"
|
189
|
+
fatal msg unless method == :get
|
190
|
+
|
175
191
|
if mode == :exact
|
176
192
|
out = Array(queue.length)
|
177
193
|
@responses.each_with_index do |response, i|
|
@@ -179,19 +195,22 @@ module Eco
|
|
179
195
|
end
|
180
196
|
elsif mode == :search
|
181
197
|
out = []
|
182
|
-
|
198
|
+
|
199
|
+
queue.each_with_index.map do |entry, _i|
|
183
200
|
pers = person(entry)
|
184
201
|
pers ||= person_match(entry)
|
185
202
|
ppl = pers ? [pers] : people_match(entry)
|
186
|
-
|
203
|
+
|
204
|
+
out += ppl
|
187
205
|
end
|
188
206
|
end
|
189
207
|
out
|
190
208
|
end
|
191
209
|
# @!endgroup
|
192
|
-
|
193
210
|
end
|
194
211
|
end
|
195
212
|
end
|
196
213
|
end
|
197
214
|
end
|
215
|
+
|
216
|
+
# rubocop:enable Naming/MethodParameterName
|
@@ -141,7 +141,7 @@ module Eco
|
|
141
141
|
msg = "starting batch '#{method}' iteration #{iteration}/#{iterations},"
|
142
142
|
msg << " with #{slice.length} entries of #{data.length} -- #{done} done"
|
143
143
|
msg << " (last: #{str_stats(start_slice, slice.length)}; total: #{str_stats(start_time, done)})"
|
144
|
-
|
144
|
+
log(:info) { msg } unless silent
|
145
145
|
|
146
146
|
start_slice = Time.now
|
147
147
|
offer_retry_on(Ecoportal::API::Errors::TimeOut) do
|
@@ -166,7 +166,7 @@ module Eco
|
|
166
166
|
# temporary working around (due to back-end problems with batch/jobs)
|
167
167
|
unless pending_for_server_error.empty?
|
168
168
|
msg = "Going to re-try #{pending_for_server_error.count} due to server errors"
|
169
|
-
|
169
|
+
log(:info) { msg } unless silent
|
170
170
|
|
171
171
|
launch_batch(
|
172
172
|
pending_for_server_error,
|
@@ -3,13 +3,12 @@ module Eco
|
|
3
3
|
class Session
|
4
4
|
class Config
|
5
5
|
class BaseConfig < Hash
|
6
|
-
attr_reader :config
|
7
|
-
|
8
6
|
class << self
|
9
7
|
def attr_key(*attrs)
|
10
8
|
attrs.each do |attr|
|
11
|
-
method =
|
12
|
-
|
9
|
+
method = attr.to_s.freeze
|
10
|
+
|
11
|
+
if instance_methods.include?(method.to_sym)
|
13
12
|
puts "WARNING (#{self}): redefining method already defined '#{method}'."
|
14
13
|
end
|
15
14
|
|
@@ -25,6 +24,10 @@ module Eco
|
|
25
24
|
end
|
26
25
|
end
|
27
26
|
|
27
|
+
include Eco::Language::AuxiliarLogger
|
28
|
+
|
29
|
+
attr_reader :config
|
30
|
+
|
28
31
|
def initialize(config:)
|
29
32
|
super(nil)
|
30
33
|
@config = config
|
@@ -40,14 +43,12 @@ module Eco
|
|
40
43
|
|
41
44
|
def clone(config:)
|
42
45
|
keys.each_with_object(self.class.new(config: config)) do |key, cnf|
|
46
|
+
cnf[key] = self[key].clone(config: cnf)
|
47
|
+
rescue ArgumentError
|
43
48
|
begin
|
44
|
-
cnf[key] = self[key].clone
|
45
|
-
rescue
|
46
|
-
|
47
|
-
cnf[key] = self[key].clone
|
48
|
-
rescue TypeError
|
49
|
-
cnf[key] = self[key]
|
50
|
-
end
|
49
|
+
cnf[key] = self[key].clone
|
50
|
+
rescue TypeError
|
51
|
+
cnf[key] = self[key]
|
51
52
|
end
|
52
53
|
end
|
53
54
|
end
|
@@ -83,14 +83,14 @@ module Eco
|
|
83
83
|
if tree
|
84
84
|
msg = "LIVE LOCATIONS Structure (#{tree.id}): '#{tree.name}' (#{tree.count} nodes)"
|
85
85
|
if first_load
|
86
|
-
|
86
|
+
log(:info) { "Using #{msg}" }
|
87
87
|
elsif switching_target
|
88
|
-
|
88
|
+
log(:info) { "Switched to #{msg}" }
|
89
89
|
else # refresh_cache
|
90
|
-
|
90
|
+
log(:debug) { "Reloading #{msg}" }
|
91
91
|
end
|
92
92
|
else
|
93
|
-
|
93
|
+
log(:info) { "Could not retrive live tree (#{id})" }
|
94
94
|
end
|
95
95
|
end
|
96
96
|
end
|
@@ -117,7 +117,9 @@ module Eco
|
|
117
117
|
Eco::API::Organization::TagTree.new(tree.treeify, id: tree.id, name: tree.name).tap do |eco_tree|
|
118
118
|
cnt = eco_tree.count
|
119
119
|
per_sec = (cnt.to_f / secs).round(2)
|
120
|
-
|
120
|
+
log(:info) {
|
121
|
+
"Loaded #{cnt} location nodes in #{secs} seconds (#{per_sec} nodes/sec)"
|
122
|
+
}
|
121
123
|
end
|
122
124
|
end
|
123
125
|
|
@@ -145,7 +147,9 @@ module Eco
|
|
145
147
|
eco_trees.push(eco_tree)
|
146
148
|
end
|
147
149
|
per_sec = (cnt.to_f / secs).round(2)
|
148
|
-
|
150
|
+
log(:info) {
|
151
|
+
"Loaded #{cnt} location nodes in #{secs} seconds (#{per_sec} nodes/sec)"
|
152
|
+
}
|
149
153
|
end
|
150
154
|
end
|
151
155
|
|
@@ -156,14 +160,6 @@ module Eco
|
|
156
160
|
|
157
161
|
apis.api(version: :graphql)
|
158
162
|
end
|
159
|
-
|
160
|
-
def session
|
161
|
-
ASSETS.session
|
162
|
-
end
|
163
|
-
|
164
|
-
def session_logger
|
165
|
-
session.logger
|
166
|
-
end
|
167
163
|
end
|
168
164
|
end
|
169
165
|
end
|
@@ -56,6 +56,7 @@ module Eco
|
|
56
56
|
|
57
57
|
def name(with_path: false)
|
58
58
|
return @name if !with_path || root?
|
59
|
+
|
59
60
|
[@_parent.name(with_path: true), @name].compact.join('.')
|
60
61
|
end
|
61
62
|
|
@@ -80,6 +81,7 @@ module Eco
|
|
80
81
|
def skip?
|
81
82
|
return @skip if instance_variable_defined?(:@skip)
|
82
83
|
return false if root?
|
84
|
+
|
83
85
|
@_parent.skip?
|
84
86
|
end
|
85
87
|
|
@@ -97,9 +99,11 @@ module Eco
|
|
97
99
|
# 2. if block is not provided, it returns the **stage** referred by `key`
|
98
100
|
def for(key = nil, &block)
|
99
101
|
raise ArgumentError, "With no 'key', a block should be given." unless key || block_given?
|
102
|
+
|
100
103
|
tap do
|
101
104
|
next yield(self) unless key
|
102
105
|
next stage(key).for(&block) if block_given?
|
106
|
+
|
103
107
|
return stage(key)
|
104
108
|
end
|
105
109
|
end
|
@@ -118,11 +122,13 @@ module Eco
|
|
118
122
|
# @return [Eco::API::Session::Config::Workflow] the current stage object (to ease chainig).
|
119
123
|
def on(key = nil, &block)
|
120
124
|
raise ArgumentError, "A block should be given." unless block_given?
|
125
|
+
|
121
126
|
if key
|
122
127
|
stage(key).on(&block)
|
123
128
|
else
|
124
129
|
@on = block
|
125
130
|
end
|
131
|
+
|
126
132
|
self
|
127
133
|
end
|
128
134
|
|
@@ -247,6 +253,7 @@ module Eco
|
|
247
253
|
|
248
254
|
def path
|
249
255
|
return name if root?
|
256
|
+
|
250
257
|
"#{@_parent.path}:#{name}"
|
251
258
|
end
|
252
259
|
|
@@ -273,7 +280,10 @@ module Eco
|
|
273
280
|
end
|
274
281
|
|
275
282
|
def run_it(io, &block)
|
276
|
-
io.session.
|
283
|
+
io.session.log(:debug) {
|
284
|
+
"(Workflow: #{path}) running now"
|
285
|
+
}
|
286
|
+
|
277
287
|
if block
|
278
288
|
io = io_result(io: io) do
|
279
289
|
io.evaluate(self, io, &block)
|
@@ -286,9 +296,11 @@ module Eco
|
|
286
296
|
end
|
287
297
|
|
288
298
|
unless ready?
|
289
|
-
|
290
|
-
|
299
|
+
io.session.log(:debug) {
|
300
|
+
"(Workflow: #{path}) 'on' callback is not defined, nor block given"
|
301
|
+
}
|
291
302
|
end
|
303
|
+
|
292
304
|
io = io_result(io: io) do
|
293
305
|
io.evaluate(self, io, &@on)
|
294
306
|
end
|
@@ -14,11 +14,9 @@ module Eco
|
|
14
14
|
|
15
15
|
def clone(name)
|
16
16
|
keys.each_with_object(self.class.new(name)) do |key, cnf|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
cnf[key] = self[key].clone
|
21
|
-
end
|
17
|
+
cnf[key] = self[key].clone(config: cnf)
|
18
|
+
rescue ArgumentError
|
19
|
+
cnf[key] = self[key].clone
|
22
20
|
end
|
23
21
|
end
|
24
22
|
|
@@ -32,7 +30,7 @@ module Eco
|
|
32
30
|
# Helper to manage `SFTP` files and folders.
|
33
31
|
# @return [Eco::API::Session::Config::SFTP]
|
34
32
|
def sftp
|
35
|
-
self["sftp"]
|
33
|
+
self["sftp"] ||= Eco::API::Session::Config::SFTP.new(config: self)
|
36
34
|
end
|
37
35
|
|
38
36
|
# Helper to upload files and folders to `S3`.
|
@@ -44,7 +42,7 @@ module Eco
|
|
44
42
|
# Helper to send emails.
|
45
43
|
# @return [Eco::API::Session::Config::Mailer]
|
46
44
|
def mailer
|
47
|
-
self["mailer"]
|
45
|
+
self["mailer"] ||= Eco::API::Session::Config::Mailer.new(config: self)
|
48
46
|
end
|
49
47
|
|
50
48
|
# Helper scope reporting structures.
|
@@ -58,7 +56,7 @@ module Eco
|
|
58
56
|
|
59
57
|
# @return [Eco::API::Session::Config::Logger]
|
60
58
|
def logger
|
61
|
-
self["logger"]
|
59
|
+
self["logger"] ||= Eco::API::Session::Config::Logger.new(config: self)
|
62
60
|
end
|
63
61
|
|
64
62
|
def log_console_level=(value)
|
@@ -86,7 +84,7 @@ module Eco
|
|
86
84
|
|
87
85
|
# @return [Eco::API::Session] the `session` linked to this `config`
|
88
86
|
def session
|
89
|
-
@session
|
87
|
+
@session ||= Eco::API::Session.new(self)
|
90
88
|
end
|
91
89
|
|
92
90
|
# @return [Eco::API::Session::Config::Apis]
|
@@ -157,7 +155,7 @@ module Eco
|
|
157
155
|
|
158
156
|
# @return [Eco::API::Session::Config::Files]
|
159
157
|
def files
|
160
|
-
self["files"]
|
158
|
+
self["files"] ||= Eco::API::Session::Config::Files.new(config: self)
|
161
159
|
end
|
162
160
|
|
163
161
|
# Defines in the base folder from where files are expected to be found when relative paths are used
|
@@ -192,22 +190,18 @@ module Eco
|
|
192
190
|
end
|
193
191
|
|
194
192
|
def require(file = nil, match: nil)
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
require_relative File.expand_path(file)
|
199
|
-
end
|
200
|
-
else
|
201
|
-
target = File.expand_path(file_manager.dir.file(file))
|
202
|
-
require_relative target
|
203
|
-
end
|
204
|
-
rescue LoadError => e
|
205
|
-
if apis.active_api.one_off?
|
206
|
-
pp e.to_s
|
207
|
-
else
|
208
|
-
raise
|
193
|
+
if match
|
194
|
+
file_manager.dir.dir_files(pattern: match).each do |file|
|
195
|
+
require_relative File.expand_path(file)
|
209
196
|
end
|
197
|
+
else
|
198
|
+
target = File.expand_path(file_manager.dir.file(file))
|
199
|
+
require_relative target
|
210
200
|
end
|
201
|
+
rescue LoadError => err
|
202
|
+
raise unless apis.active_api.one_off?
|
203
|
+
|
204
|
+
pp err.to_s
|
211
205
|
end
|
212
206
|
# @!endgroup
|
213
207
|
|
@@ -403,7 +397,7 @@ module Eco
|
|
403
397
|
|
404
398
|
# @return [Eco::API::Session::Config::Workflow]
|
405
399
|
def workflow
|
406
|
-
@workflow = self["workflow"]
|
400
|
+
@workflow = self["workflow"] ||= Eco::API::Session::Config::Workflow.new(config: self)
|
407
401
|
@workflow.tap do |wf|
|
408
402
|
yield(wf) if block_given?
|
409
403
|
end
|
@@ -421,7 +415,6 @@ module Eco
|
|
421
415
|
self["delay_between_job_groups"]
|
422
416
|
end
|
423
417
|
# @!endgroup
|
424
|
-
|
425
418
|
end
|
426
419
|
end
|
427
420
|
end
|
data/lib/eco/api/session.rb
CHANGED
@@ -22,7 +22,9 @@ module Eco
|
|
22
22
|
@entry_factories = {}
|
23
23
|
@person_factories = {}
|
24
24
|
|
25
|
-
|
25
|
+
log(:debug) {
|
26
|
+
"LINE COMMAND: #{$0} #{ARGV.join(" ")}" # rubocop:disable Style/SpecialGlobalVars
|
27
|
+
}
|
26
28
|
end
|
27
29
|
|
28
30
|
# @retrun [String] the name of the current environment
|
@@ -327,7 +329,9 @@ module Eco
|
|
327
329
|
if mailer?
|
328
330
|
mailer.mail(**kargs)
|
329
331
|
else
|
330
|
-
|
332
|
+
log(:error) {
|
333
|
+
"You are trying to use the mailer, but it's not configured"
|
334
|
+
}
|
331
335
|
nil
|
332
336
|
end
|
333
337
|
end
|
@@ -353,12 +357,17 @@ module Eco
|
|
353
357
|
elsif directory
|
354
358
|
path = s3uploader.upload_directory(directory, recurse: recurse)
|
355
359
|
else
|
356
|
-
|
360
|
+
log(:error) {
|
361
|
+
"To use Session.s3upload, you must specify either directory, file or content and file name"
|
362
|
+
}
|
357
363
|
end
|
358
364
|
return path unless link
|
365
|
+
|
359
366
|
s3uploader.link(path)
|
360
367
|
else
|
361
|
-
|
368
|
+
log(:error) {
|
369
|
+
"You are trying to use S3 uploader, but it's not configured"
|
370
|
+
}
|
362
371
|
nil
|
363
372
|
end
|
364
373
|
end
|
data/lib/eco/api/usecases/cli.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
class Eco::API::UseCases::Default::Locations::CodesToTagsCase
|
2
|
+
# Class to define the CLI integration of a usecase anywhere it suits.
|
3
|
+
class Cli < Eco::API::UseCases::Cli
|
4
|
+
str = "Adds a column 'ecoPortalTag' to the input CSV "
|
5
|
+
str << "with the tags that the location codes map to"
|
6
|
+
desc str
|
7
|
+
|
8
|
+
callback do |_sess, options, _case|
|
9
|
+
file = SCR.get_file(cli_name, required: true, should_exist: true)
|
10
|
+
options.deep_merge!(other: {file: {name: file, format: :csv}})
|
11
|
+
end
|
12
|
+
|
13
|
+
add_option("-column", "Specify the input column header with the codes") do |options|
|
14
|
+
col_codes = SCR.get_arg("-column", with_param: true)
|
15
|
+
options.deep_merge!(other: {file: {codes_column: col_codes}})
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class Eco::API::UseCases::Default::Locations::CsvToTree
|
2
|
+
# Class to define the CLI integration of a usecase anywhere it suits.
|
3
|
+
class Cli < Eco::API::UseCases::Cli
|
4
|
+
str = "Creates a JSON file with the tagtree from a CSV file"
|
5
|
+
desc str
|
6
|
+
|
7
|
+
callback do |_sess, options, _case|
|
8
|
+
file = SCR.get_file(cli_name, required: true, should_exist: true)
|
9
|
+
options.deep_merge!(source: {file: file})
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class Eco::API::UseCases::Default::Locations::TagTreePaths
|
2
|
+
# Class to define the CLI integration of a usecase anywhere it suits.
|
3
|
+
class Cli < Eco::API::UseCases::Cli
|
4
|
+
str = "Creates a CSV with the paths to each tag"
|
5
|
+
desc str
|
6
|
+
|
7
|
+
add_option("-column", "Specify the input column header with the codes") do |options|
|
8
|
+
col_codes = SCR.get_arg("-column", with_param: true)
|
9
|
+
options.deep_merge!(other: {file: {codes_column: col_codes}})
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -2,22 +2,30 @@ class Eco::API::UseCases::Default::Locations::CodesToTagsCase < Eco::API::Common
|
|
2
2
|
name "codes-to-tags-from"
|
3
3
|
type :other
|
4
4
|
|
5
|
+
require_relative 'cli/codes_to_tags_cli'
|
6
|
+
|
7
|
+
def main(*_args)
|
8
|
+
options[:end_get] = false
|
9
|
+
codes_to_tags
|
10
|
+
end
|
11
|
+
|
5
12
|
def codes_to_tags
|
6
|
-
|
13
|
+
msg = "You have not defined a tagtree for the organisation"
|
14
|
+
raise msg unless session.tagtree
|
15
|
+
|
7
16
|
csv_table = Eco::CSV.read(input_file)
|
8
17
|
|
9
|
-
csv_table.add_column("ecoPortalTag").tap do |
|
10
|
-
|
18
|
+
csv_table.add_column("ecoPortalTag").tap do |table|
|
19
|
+
table.each do |row|
|
11
20
|
row["ecoPortalTag"] = to_tag(row[codes_column])
|
12
21
|
end
|
13
22
|
|
14
|
-
File.open(output_file, "w") {|fd| fd <<
|
15
|
-
end
|
16
|
-
end
|
23
|
+
File.open(output_file, "w") {|fd| fd << table.to_csv}
|
17
24
|
|
18
|
-
|
19
|
-
|
20
|
-
|
25
|
+
log(:info) {
|
26
|
+
"Generated '#{output_file}' file"
|
27
|
+
}
|
28
|
+
end
|
21
29
|
end
|
22
30
|
|
23
31
|
private
|
@@ -28,15 +36,22 @@ class Eco::API::UseCases::Default::Locations::CodesToTagsCase < Eco::API::Common
|
|
28
36
|
elsif session.tagtree.tag?(code)
|
29
37
|
code.upcase
|
30
38
|
else
|
31
|
-
|
39
|
+
log(:warn) { "Unknown Location Code: '#{code}'" }
|
32
40
|
nil
|
33
41
|
end
|
34
42
|
end
|
35
43
|
|
36
44
|
def mapper
|
37
|
-
|
38
|
-
|
45
|
+
return @mapper if instance_variable_defined?(:@mapper)
|
46
|
+
|
47
|
+
@mapper = session.config.locations_mapper if session.config.location_codes
|
48
|
+
|
49
|
+
unless @mapper
|
50
|
+
msg = "No filter_tags parser, nor location mappings are present"
|
51
|
+
raise msg
|
39
52
|
end
|
53
|
+
|
54
|
+
@mapper
|
40
55
|
end
|
41
56
|
|
42
57
|
def codes_column
|
@@ -48,7 +63,11 @@ class Eco::API::UseCases::Default::Locations::CodesToTagsCase < Eco::API::Common
|
|
48
63
|
end
|
49
64
|
|
50
65
|
def output_file
|
51
|
-
"mapped_#{clean_file_name(input_file)}"
|
66
|
+
File.join(output_folder, "mapped_#{clean_file_name(input_file)}")
|
67
|
+
end
|
68
|
+
|
69
|
+
def output_folder
|
70
|
+
File.dirname(input_file)
|
52
71
|
end
|
53
72
|
|
54
73
|
def clean_file_name(filename)
|