eco-helpers 2.0.44 → 2.0.45
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -3
- data/eco-helpers.gemspec +1 -1
- data/lib/eco/api/usecases/ooze_samples/register_export_case.rb +184 -0
- data/lib/eco/api/usecases/ooze_samples.rb +1 -0
- data/lib/eco/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f85bd156250d1f44ca911d98007005cbbb2281ff4a40a2fc07a80680fd42a408
|
4
|
+
data.tar.gz: 4ccda90fbf7d1bbfc814d18cd033110b7af2ae366687af1fa2db10370788c52d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4b7add6e04fb8b4dfa0c56371bc3f85e791659754e937f60586b88dec06186723f9286c87482144bd9b012298dbc03251388c49f1245008026a186cd6d16a88
|
7
|
+
data.tar.gz: 7a0bfda7154a8c0e7bb7e18100a96cd2a45f26a6d45309725e7d796dd9d0ad48cefb35be551c031706757d1241fab7505d74f401cf6a04764547bbe8c582e076
|
data/CHANGELOG.md
CHANGED
@@ -1,15 +1,22 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
-
## [2.0.
|
4
|
+
## [2.0.45] - 2021-11-xx
|
5
5
|
|
6
6
|
### Added
|
7
|
-
|
7
|
+
- `Eco::API::UseCases::OozeSamples::RegisterExportCase`
|
8
|
+
|
8
9
|
### Changed
|
9
10
|
- Upgrade `ecoportal-api` dependency
|
10
|
-
|
11
|
+
- Upgrade `ecoportal-api-v2` dependency
|
12
|
+
|
11
13
|
### Fixed
|
12
14
|
|
15
|
+
## [2.0.44] - 2021-11-25
|
16
|
+
|
17
|
+
### Changed
|
18
|
+
- Upgrade `ecoportal-api` dependency
|
19
|
+
|
13
20
|
## [2.0.43] - 2021-11-25
|
14
21
|
|
15
22
|
### Added
|
data/eco-helpers.gemspec
CHANGED
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.add_development_dependency "redcarpet", ">= 3.5.1", "< 3.6"
|
32
32
|
|
33
33
|
spec.add_dependency 'ecoportal-api', '>= 0.8.4', '< 0.9'
|
34
|
-
spec.add_dependency 'ecoportal-api-v2', '>= 0.8.
|
34
|
+
spec.add_dependency 'ecoportal-api-v2', '>= 0.8.21', '< 0.9'
|
35
35
|
spec.add_dependency 'aws-sdk-s3', '>= 1.83.0', '< 2'
|
36
36
|
spec.add_dependency 'aws-sdk-ses', '>= 1.36.0', '< 2'
|
37
37
|
spec.add_dependency 'dotenv', '>= 2.7.6', '< 2.8'
|
@@ -0,0 +1,184 @@
|
|
1
|
+
# Use case to update a register
|
2
|
+
# @note
|
3
|
+
# - You can define methods `filters` and `search` to change the target entries of the register
|
4
|
+
# - You need to define the `process_ooze` method
|
5
|
+
# This case expects `options[:source][:register_id]`
|
6
|
+
class Eco::API::UseCases::OozeSamples::RegisterExportCase < Eco::API::Common::Loaders::UseCase
|
7
|
+
|
8
|
+
class << self
|
9
|
+
# @return [Integer] the number of pages to be processed in each batch
|
10
|
+
def batch_size(size = nil)
|
11
|
+
@batch_size ||= 25
|
12
|
+
return @batch_size unless size
|
13
|
+
@batch_size = size
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
include Eco::API::UseCases::OozeSamples::Helpers
|
18
|
+
|
19
|
+
name "register-export-case"
|
20
|
+
type :other
|
21
|
+
|
22
|
+
attr_reader :session, :options, :usecase
|
23
|
+
attr_reader :target
|
24
|
+
|
25
|
+
def main(session, options, usecase)
|
26
|
+
options[:end_get] = false
|
27
|
+
@session = session; @options = options; @usecase = usecase
|
28
|
+
@target = nil
|
29
|
+
raise "You need to inherit from this class ('#{self.class}') and call super with a block" unless block_given?
|
30
|
+
with_each_entry do |ooze|
|
31
|
+
process_ooze(ooze)
|
32
|
+
end
|
33
|
+
yield
|
34
|
+
end
|
35
|
+
|
36
|
+
# Write here your script
|
37
|
+
def process_ooze(ooze = target)
|
38
|
+
raise "You need to inherit from this class ('#{self.class}') and call super with a block" unless block_given?
|
39
|
+
yield(ooze)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def new_target(object)
|
45
|
+
@target = object
|
46
|
+
end
|
47
|
+
|
48
|
+
def with_each_entry
|
49
|
+
batched_search_results do |page_results|
|
50
|
+
page_results.each do |page_result|
|
51
|
+
if ooz = build_full_ooze(page_result.id)
|
52
|
+
yield(ooz)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# It builds a full page model (not updatable)
|
59
|
+
# @note If it's a page instance with stages, there's where it will be handy
|
60
|
+
# @param ooze_id [String]
|
61
|
+
# @return [Ecoportal::API::V2::Page]
|
62
|
+
def build_full_ooze(ooze_id)
|
63
|
+
if page = ooze(ooze_id)
|
64
|
+
return page unless page.is_a?(Ecoportal::API::V2::Pages::PageStage)
|
65
|
+
secs_doc = page.sections.doc
|
66
|
+
flds_doc = page.components.doc
|
67
|
+
pending_stage_ids = page.stages.map(&:id) - [page.current_stage_id]
|
68
|
+
pending_stage_ids.each do |id|
|
69
|
+
if page = stage(id, ooze: page)
|
70
|
+
page.sections.doc.each do |sec_doc|
|
71
|
+
unless secs_doc.find {|sec| sec["id"] == sec_doc["id"]}
|
72
|
+
secs_doc << sec_doc
|
73
|
+
end
|
74
|
+
end
|
75
|
+
page.components.doc.each do |comp_doc|
|
76
|
+
unless flds_doc.find {|fld| fld["id"] == comp_doc["id"]}
|
77
|
+
flds_doc << comp_doc
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
Ecoportal::API::V2::Page.new(page.doc)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
#def update_oozes(batched_oozes = batch_queue)
|
87
|
+
# batched_oozes.each do |ooze|
|
88
|
+
# update_ooze(ooze)
|
89
|
+
# end
|
90
|
+
# batched_oozes.clear
|
91
|
+
#end
|
92
|
+
|
93
|
+
def batched_search_results
|
94
|
+
raise "Missing block. It yields in slices of #{self.class.batch_size} results" unless block_given?
|
95
|
+
results_preview
|
96
|
+
results = []
|
97
|
+
apiv2.registers.search(register_id, search_options) do |page_result|
|
98
|
+
results << page_result
|
99
|
+
if results.length >= self.class.batch_size
|
100
|
+
yield(results)
|
101
|
+
results = []
|
102
|
+
end
|
103
|
+
end
|
104
|
+
yield(results) unless results.empty?
|
105
|
+
end
|
106
|
+
|
107
|
+
def ooze(ooze_id = nil, stage_id: nil)
|
108
|
+
return target unless ooze_id
|
109
|
+
apiv2.pages.get(ooze_id, stage_id: stage_id).tap do |ooze|
|
110
|
+
if ooze
|
111
|
+
new_target(ooze)
|
112
|
+
logger.info("Got #{object_reference(ooze)}")
|
113
|
+
else
|
114
|
+
exit_error "Could not get ooze '#{ooze_id}'"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def stage(id_name = nil, ooze: target)
|
120
|
+
if ooze_id = ooze && ooze.id
|
121
|
+
exit_error "#{object_reference(ooze)} does not have stages!" unless ooze.stages?
|
122
|
+
else
|
123
|
+
exit_error "There's no target ooze to get retrieve stages from"
|
124
|
+
end
|
125
|
+
|
126
|
+
if stg = ooze.stages[id_name] || ooze.stages.get_by_name(id_name)
|
127
|
+
return ooze if ooze.respond_to?(:current_stage_id) && (ooze.current_stage_id == stg.id)
|
128
|
+
return apiv2.pages.get(ooze_id, stage_id: stg.id).tap do |stage|
|
129
|
+
if stage
|
130
|
+
new_target(stage)
|
131
|
+
logger.info("Got #{object_reference(stage)} from #{object_reference(ooze)}")
|
132
|
+
else
|
133
|
+
exit_error "Could not get stage '#{id_name}' in ooze '#{ooze_id}'"
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
exit_error "Stage '#{id_name}' doesn't exist in ooze '#{ooze_id}'"
|
138
|
+
end
|
139
|
+
|
140
|
+
def results_preview
|
141
|
+
apiv2.registers.search(register_id, search_options.merge(only_first: true)).tap do |search_results|
|
142
|
+
str_results = "Total target entries: #{search_results.total} (out of #{search_results.total_before_filtering})"
|
143
|
+
session.prompt_user("Do you want to proceed (y/N):", explanation: str_results, default: "N", timeout: 10) do |res|
|
144
|
+
unless res.upcase.start_with?("Y")
|
145
|
+
puts "..."
|
146
|
+
logger.info "Aborting script..."
|
147
|
+
exit(0)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def search_options
|
154
|
+
@search_options ||= {}.tap do |opts|
|
155
|
+
opts.merge!(sort: "created_at")
|
156
|
+
opts.merge!(dir: "asc")
|
157
|
+
opts.merge!(query: conf_search) if conf_search
|
158
|
+
opts.merge!(filters: conf_filters)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def conf_filters
|
163
|
+
return filters if self.respond_to?(:filters)
|
164
|
+
[]
|
165
|
+
end
|
166
|
+
|
167
|
+
def conf_search
|
168
|
+
return search if self.respond_to?(:search)
|
169
|
+
end
|
170
|
+
|
171
|
+
def register_id
|
172
|
+
options.dig(:source, :register_id)
|
173
|
+
end
|
174
|
+
|
175
|
+
def apiv2
|
176
|
+
@apiv2 ||= session.api(version: :oozes)
|
177
|
+
end
|
178
|
+
|
179
|
+
def exit_error(msg)
|
180
|
+
logger.error(msg)
|
181
|
+
exit(1)
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
@@ -10,6 +10,7 @@ end
|
|
10
10
|
|
11
11
|
require_relative 'ooze_samples/helpers'
|
12
12
|
require_relative 'ooze_samples/ooze_base_case'
|
13
|
+
require_relative 'ooze_samples/register_export_case'
|
13
14
|
require_relative 'ooze_samples/ooze_run_base_case'
|
14
15
|
require_relative 'ooze_samples/ooze_update_case'
|
15
16
|
require_relative 'ooze_samples/ooze_from_doc_case'
|
data/lib/eco/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eco-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.45
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oscar Segura
|
@@ -136,7 +136,7 @@ dependencies:
|
|
136
136
|
requirements:
|
137
137
|
- - ">="
|
138
138
|
- !ruby/object:Gem::Version
|
139
|
-
version: 0.8.
|
139
|
+
version: 0.8.21
|
140
140
|
- - "<"
|
141
141
|
- !ruby/object:Gem::Version
|
142
142
|
version: '0.9'
|
@@ -146,7 +146,7 @@ dependencies:
|
|
146
146
|
requirements:
|
147
147
|
- - ">="
|
148
148
|
- !ruby/object:Gem::Version
|
149
|
-
version: 0.8.
|
149
|
+
version: 0.8.21
|
150
150
|
- - "<"
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0.9'
|
@@ -564,6 +564,7 @@ files:
|
|
564
564
|
- lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
|
565
565
|
- lib/eco/api/usecases/ooze_samples/ooze_run_base_case.rb
|
566
566
|
- lib/eco/api/usecases/ooze_samples/ooze_update_case.rb
|
567
|
+
- lib/eco/api/usecases/ooze_samples/register_export_case.rb
|
567
568
|
- lib/eco/api/usecases/ooze_samples/register_update_case.rb
|
568
569
|
- lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb
|
569
570
|
- lib/eco/api/usecases/use_case.rb
|