eco-helpers 3.0.18 → 3.0.19
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 +20 -3
- data/eco-helpers.gemspec +3 -3
- data/lib/eco/api/common/loaders/parser.rb +10 -0
- data/lib/eco/api/common/people/default_parsers/csv_parser.rb +21 -208
- data/lib/eco/api/common/people/default_parsers/helpers/expected_headers.rb +206 -0
- data/lib/eco/api/common/people/default_parsers/helpers/null_parsing.rb +36 -0
- data/lib/eco/api/common/people/default_parsers/helpers.rb +15 -0
- data/lib/eco/api/common/people/default_parsers/json_parser.rb +56 -0
- data/lib/eco/api/common/people/default_parsers/xls_parser.rb +13 -14
- data/lib/eco/api/common/people/default_parsers.rb +2 -0
- data/lib/eco/api/common/people/entry_factory.rb +15 -4
- data/lib/eco/api/session/batch/launcher/status_handling.rb +4 -2
- data/lib/eco/api/session/batch/launcher.rb +3 -3
- data/lib/eco/api/session.rb +2 -0
- data/lib/eco/api/usecases/default/utils/cli/group_csv_cli.rb +26 -0
- data/lib/eco/api/usecases/default/utils/cli/json_to_csv_cli.rb +10 -0
- data/lib/eco/api/usecases/default/utils/cli/sort_csv_cli.rb +17 -0
- data/lib/eco/api/usecases/default/utils/cli/split_json_cli.rb +15 -0
- data/lib/eco/api/usecases/default/utils/group_csv_case.rb +213 -0
- data/lib/eco/api/usecases/default/utils/json_to_csv_case.rb +71 -0
- data/lib/eco/api/usecases/default/utils/sort_csv_case.rb +127 -0
- data/lib/eco/api/usecases/default/utils/split_json_case.rb +224 -0
- data/lib/eco/api/usecases/default/utils.rb +4 -0
- data/lib/eco/version.rb +1 -1
- metadata +21 -9
@@ -0,0 +1,224 @@
|
|
1
|
+
class Eco::API::UseCases::Default::Utils::SplitJson < Eco::API::Common::Loaders::UseCase
|
2
|
+
require_relative 'cli/split_json_cli'
|
3
|
+
|
4
|
+
MAX_ITEMS = 15_000
|
5
|
+
|
6
|
+
name "split-json"
|
7
|
+
type :other
|
8
|
+
|
9
|
+
def main(*_args)
|
10
|
+
if simulate?
|
11
|
+
count = input_json.count
|
12
|
+
log(:info) { "JSON '#{input_file}' has #{count} elements." }
|
13
|
+
else
|
14
|
+
split_json_into_files!
|
15
|
+
|
16
|
+
msg = []
|
17
|
+
msg << "Total elements: #{total_count}"
|
18
|
+
msg << "Generated files:"
|
19
|
+
out_files.each do |file|
|
20
|
+
msg << " * #{file}'"
|
21
|
+
end
|
22
|
+
|
23
|
+
log(:info) { msg.join("\n") }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def split_json_into_files!
|
30
|
+
first = true
|
31
|
+
|
32
|
+
while pending?
|
33
|
+
swap_file! if first
|
34
|
+
first = false
|
35
|
+
|
36
|
+
curr_json << input_json.shift
|
37
|
+
next_count!
|
38
|
+
|
39
|
+
swap_file! if split?
|
40
|
+
end
|
41
|
+
|
42
|
+
generate_file!
|
43
|
+
end
|
44
|
+
|
45
|
+
def split?
|
46
|
+
return false unless curr_count > max_items
|
47
|
+
|
48
|
+
true
|
49
|
+
end
|
50
|
+
|
51
|
+
def max_items
|
52
|
+
@max_items ||= max_items_options || self.class::MAX_ITEMS
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
# OPTIONS
|
57
|
+
|
58
|
+
def max_items_options
|
59
|
+
return unless (num = options.dig(:output, :file, :max_items))
|
60
|
+
|
61
|
+
num = num.to_i
|
62
|
+
num = nil if num.zero?
|
63
|
+
num
|
64
|
+
end
|
65
|
+
|
66
|
+
# OUTPUT JSON
|
67
|
+
|
68
|
+
# Returns the last json array and blanks the variable
|
69
|
+
def exporting_json!
|
70
|
+
curr_json.tap do
|
71
|
+
@curr_json = []
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def curr_json
|
76
|
+
@curr_json ||= []
|
77
|
+
end
|
78
|
+
|
79
|
+
def pending?
|
80
|
+
!input_json.empty?
|
81
|
+
end
|
82
|
+
|
83
|
+
def input_json
|
84
|
+
@json ||= JSON.load(File.open(input_file, 'r'))
|
85
|
+
end
|
86
|
+
|
87
|
+
# COUNTS
|
88
|
+
|
89
|
+
def next_count!
|
90
|
+
@curr_count = curr_count + 1
|
91
|
+
@total_count = total_count + 1
|
92
|
+
end
|
93
|
+
|
94
|
+
def total_count
|
95
|
+
@total_count ||= 0
|
96
|
+
end
|
97
|
+
|
98
|
+
def curr_count
|
99
|
+
@curr_count ||= 0
|
100
|
+
end
|
101
|
+
|
102
|
+
def new_count!
|
103
|
+
@curr_count = 0
|
104
|
+
end
|
105
|
+
|
106
|
+
# FILE GENERATION
|
107
|
+
|
108
|
+
def swap_file!
|
109
|
+
generate_file!
|
110
|
+
next_file!
|
111
|
+
end
|
112
|
+
|
113
|
+
def generate_file!
|
114
|
+
return unless @curr_file
|
115
|
+
|
116
|
+
if curr_json.empty?
|
117
|
+
log(:info) {
|
118
|
+
msg = "No pending elements to be transferred "
|
119
|
+
msg << "(skipping creation of file '#{curr_file}')"
|
120
|
+
msg
|
121
|
+
}
|
122
|
+
out_files -= [curr_file]
|
123
|
+
return
|
124
|
+
end
|
125
|
+
|
126
|
+
log(:info) {
|
127
|
+
msg = "Generating file at elem #{total_count} "
|
128
|
+
msg << "(file elements: #{curr_count})"
|
129
|
+
msg
|
130
|
+
}
|
131
|
+
|
132
|
+
save_json(exporting_json!, curr_file)
|
133
|
+
new_count!
|
134
|
+
end
|
135
|
+
|
136
|
+
def save_json(data, file)
|
137
|
+
File.open(file, 'w') do |fd|
|
138
|
+
first = true
|
139
|
+
|
140
|
+
fd << '['
|
141
|
+
data.each do |elem|
|
142
|
+
fd << "," unless first
|
143
|
+
first = false
|
144
|
+
|
145
|
+
fd << elem.to_json
|
146
|
+
end
|
147
|
+
fd << ']'
|
148
|
+
end.tap do
|
149
|
+
log(:info) {
|
150
|
+
"Generated file '#{file}'"
|
151
|
+
}
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
# OUTPUT FILES
|
156
|
+
attr_reader :curr_file
|
157
|
+
|
158
|
+
def file_count
|
159
|
+
@file_count ||= 0
|
160
|
+
end
|
161
|
+
|
162
|
+
def next_file!
|
163
|
+
@file_count = file_count + 1
|
164
|
+
@curr_file = generate_name(@file_count)
|
165
|
+
@curr_file.tap do
|
166
|
+
out_files << @curr_file
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def out_files
|
171
|
+
@out_files ||= []
|
172
|
+
end
|
173
|
+
|
174
|
+
def generate_name(fidx)
|
175
|
+
File.join(input_dir, "#{input_name}_#{file_number(fidx)}#{input_ext}")
|
176
|
+
end
|
177
|
+
|
178
|
+
def file_number(num)
|
179
|
+
"#{zeroed}#{num}"[-5..]
|
180
|
+
end
|
181
|
+
|
182
|
+
def zeroed
|
183
|
+
"0" * 5
|
184
|
+
end
|
185
|
+
|
186
|
+
# INPUT FILE
|
187
|
+
|
188
|
+
def input_name
|
189
|
+
@input_name ||= File.basename(input_basename, input_ext)
|
190
|
+
end
|
191
|
+
|
192
|
+
def input_ext
|
193
|
+
@input_ext ||= input_basename.split('.')[1..].join('.').then do |name|
|
194
|
+
".#{name}"
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
def input_basename
|
199
|
+
@input_basename ||= File.basename(input_full_filename)
|
200
|
+
end
|
201
|
+
|
202
|
+
def input_dir
|
203
|
+
@input_dir = File.dirname(input_full_filename)
|
204
|
+
end
|
205
|
+
|
206
|
+
def input_full_filename
|
207
|
+
@input_full_filename ||= File.expand_path(input_file)
|
208
|
+
end
|
209
|
+
|
210
|
+
def input_file
|
211
|
+
options.dig(:source, :file).tap do |file|
|
212
|
+
next if file && File.exist?(file)
|
213
|
+
|
214
|
+
unless file
|
215
|
+
log(:warn) { 'No input file provided' }
|
216
|
+
exit 1
|
217
|
+
end
|
218
|
+
|
219
|
+
log(:warn) {
|
220
|
+
"File '#{file}' doesn't exist"
|
221
|
+
}
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
data/lib/eco/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eco-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oscar Segura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -229,7 +229,7 @@ dependencies:
|
|
229
229
|
version: '0.10'
|
230
230
|
- - ">="
|
231
231
|
- !ruby/object:Gem::Version
|
232
|
-
version: 0.10.
|
232
|
+
version: 0.10.7
|
233
233
|
type: :runtime
|
234
234
|
prerelease: false
|
235
235
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -239,7 +239,7 @@ dependencies:
|
|
239
239
|
version: '0.10'
|
240
240
|
- - ">="
|
241
241
|
- !ruby/object:Gem::Version
|
242
|
-
version: 0.10.
|
242
|
+
version: 0.10.7
|
243
243
|
- !ruby/object:Gem::Dependency
|
244
244
|
name: ecoportal-api-graphql
|
245
245
|
requirement: !ruby/object:Gem::Requirement
|
@@ -249,7 +249,7 @@ dependencies:
|
|
249
249
|
version: '0.4'
|
250
250
|
- - ">="
|
251
251
|
- !ruby/object:Gem::Version
|
252
|
-
version: 0.4.
|
252
|
+
version: 0.4.3
|
253
253
|
type: :runtime
|
254
254
|
prerelease: false
|
255
255
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -259,7 +259,7 @@ dependencies:
|
|
259
259
|
version: '0.4'
|
260
260
|
- - ">="
|
261
261
|
- !ruby/object:Gem::Version
|
262
|
-
version: 0.4.
|
262
|
+
version: 0.4.3
|
263
263
|
- !ruby/object:Gem::Dependency
|
264
264
|
name: ecoportal-api-v2
|
265
265
|
requirement: !ruby/object:Gem::Requirement
|
@@ -269,7 +269,7 @@ dependencies:
|
|
269
269
|
version: '2.0'
|
270
270
|
- - ">="
|
271
271
|
- !ruby/object:Gem::Version
|
272
|
-
version: 2.0.
|
272
|
+
version: 2.0.12
|
273
273
|
type: :runtime
|
274
274
|
prerelease: false
|
275
275
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -279,7 +279,7 @@ dependencies:
|
|
279
279
|
version: '2.0'
|
280
280
|
- - ">="
|
281
281
|
- !ruby/object:Gem::Version
|
282
|
-
version: 2.0.
|
282
|
+
version: 2.0.12
|
283
283
|
- !ruby/object:Gem::Dependency
|
284
284
|
name: ed25519
|
285
285
|
requirement: !ruby/object:Gem::Requirement
|
@@ -551,6 +551,10 @@ files:
|
|
551
551
|
- lib/eco/api/common/people/default_parsers/csv_parser.rb
|
552
552
|
- lib/eco/api/common/people/default_parsers/date_parser.rb
|
553
553
|
- lib/eco/api/common/people/default_parsers/freemium_parser.rb
|
554
|
+
- lib/eco/api/common/people/default_parsers/helpers.rb
|
555
|
+
- lib/eco/api/common/people/default_parsers/helpers/expected_headers.rb
|
556
|
+
- lib/eco/api/common/people/default_parsers/helpers/null_parsing.rb
|
557
|
+
- lib/eco/api/common/people/default_parsers/json_parser.rb
|
554
558
|
- lib/eco/api/common/people/default_parsers/login_providers_parser.rb
|
555
559
|
- lib/eco/api/common/people/default_parsers/multi_parser.rb
|
556
560
|
- lib/eco/api/common/people/default_parsers/numeric_parser.rb
|
@@ -735,8 +739,16 @@ files:
|
|
735
739
|
- lib/eco/api/usecases/default/people/utils/switch_supervisor_case.rb
|
736
740
|
- lib/eco/api/usecases/default/people/utils/transfer_account_case.rb
|
737
741
|
- lib/eco/api/usecases/default/utils.rb
|
742
|
+
- lib/eco/api/usecases/default/utils/cli/group_csv_cli.rb
|
743
|
+
- lib/eco/api/usecases/default/utils/cli/json_to_csv_cli.rb
|
744
|
+
- lib/eco/api/usecases/default/utils/cli/sort_csv_cli.rb
|
738
745
|
- lib/eco/api/usecases/default/utils/cli/split_csv_cli.rb
|
746
|
+
- lib/eco/api/usecases/default/utils/cli/split_json_cli.rb
|
747
|
+
- lib/eco/api/usecases/default/utils/group_csv_case.rb
|
748
|
+
- lib/eco/api/usecases/default/utils/json_to_csv_case.rb
|
749
|
+
- lib/eco/api/usecases/default/utils/sort_csv_case.rb
|
739
750
|
- lib/eco/api/usecases/default/utils/split_csv_case.rb
|
751
|
+
- lib/eco/api/usecases/default/utils/split_json_case.rb
|
740
752
|
- lib/eco/api/usecases/default_cases.rb
|
741
753
|
- lib/eco/api/usecases/default_cases/create_case.rb
|
742
754
|
- lib/eco/api/usecases/default_cases/delete_sync_case.rb
|
@@ -951,7 +963,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
951
963
|
- !ruby/object:Gem::Version
|
952
964
|
version: '0'
|
953
965
|
requirements: []
|
954
|
-
rubygems_version: 3.5.
|
966
|
+
rubygems_version: 3.5.23
|
955
967
|
signing_key:
|
956
968
|
specification_version: 4
|
957
969
|
summary: eco-helpers to manage people api cases
|