eco-helpers 2.0.53 → 2.0.56

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 71ac6b334999283d1bab07efdb1ece3fdbbfaa56052f292010a3741faad92351
4
- data.tar.gz: e432429671478dcca99ef444f1db0eeab66d9ad2dc7150cfc12577fb06f5b1e7
3
+ metadata.gz: c9227a13716393bdd79a7bdf3d4729dbc2b426f43e16d1525001ffd0a2c58bb4
4
+ data.tar.gz: 00adb8c5c5abc08e53e4130a1cdf9ff03cf4307ac86c4cbe8e84ebffd8ba2458
5
5
  SHA512:
6
- metadata.gz: ff99f0de94a2e87730f2d6b8496d4d556cbfe7ec3bb99289f3e27cf30512e0644b33f142f0664ee2c5f9f91e7fc13b83bc62178af26f3e0929668acd94f95088
7
- data.tar.gz: 3b9b43011552a1cb9f37a46c18cabab8ad2892b3634908895ddd99b2269151c65bd3a4c5a6281ab080396ea3ec0890f29fd5f1e37c8427d80bbdb2c2e240b91f
6
+ metadata.gz: 0c69583967b50677bf012fdd354d3fb17abf521fcceb702f71ccfbfd942fb1e11963ff50b103f351e9cbebcfd531751dc9c54094e6b645c40b0e77d5ef6c7d8b
7
+ data.tar.gz: 60a0e1e311f8a3aae34bbfcf1f4c5dccf3bd541dfaef0ab60b3f7b557a69bc6b5f7a74febdea0a85aa4db658c508da69fef99753c89459db0eab58112c577bc2
data/CHANGELOG.md CHANGED
@@ -1,17 +1,46 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [2.0.53] - 2022-03-xx
4
+ ## [2.0.56] - 2022-04-xx
5
+
6
+ ### Added
7
+ - `Eco::API::UseCases::OozeSamples::OozeBaseCase#add_field_by_doc`
8
+ - Same as `#add_field` but using an existing _**doc**_ as a model
9
+
10
+ ### Changed
11
+ - `ecoportal-api-v2` dependency upgrade
12
+ - `Eco::API::Common::Session::FileManager#file_content`
13
+ - added parameter `mode:` to options can be used as well
14
+ - `Eco::API::UseCases::OozeSamples::Helpers::Shortcuts#same_string?`
15
+ - Added parameter `mild:` to compare the strings with only alphabetic characters
16
+ - `Eco::API::UseCases::OozeSamples::OozeRunBaseCase`
17
+ - `#main` and `#process_ooze` methods were not obvious to use
18
+ - `Eco::API::UseCases::OozeSamples::RegisterUpdateCase` slight change on the **`run` summary message**
19
+
20
+ ### Fixed
21
+ - `Eco::API::UseCases::OozeSamples::OozeBaseCase#update_ooze`
22
+ - Added call to `validate` also when we are on `dry-run` **mode**
23
+
24
+ ## [2.0.55] - 2022-04-04
25
+
26
+ ### Fixed
27
+ - `Eco::API::UseCases::DefaultCases::Samples::Sftp` should move the basename to Windows compatible chars.
28
+
29
+ ## [2.0.54] - 2022-04-04
30
+
31
+ ### Added
32
+ - `Eco::API::UseCases::DefaultCases::Samples::Sftp` should tell where the files went in the local.
33
+
34
+
35
+ ## [2.0.53] - 2022-04-04
5
36
 
6
37
  ### Added
7
38
  - `Eco::API::MicroCases#set_supervisor` prevent to set someone as supervisor of themselves.
8
39
  - `Eco::API::UseCases::DefaultCases::Samples::Sftp` integration to modify the `source_folder`
9
-
40
+
10
41
  ### Changed
11
42
  - upgrade `ecoportal-api` and `ecoportal-api-v2` dependencies
12
43
 
13
- ### Fixed
14
-
15
44
  ## [2.0.52] - 2022-03-04
16
45
 
17
46
  ### 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.5', '< 0.9'
34
- spec.add_dependency 'ecoportal-api-v2', '>= 0.8.26', '< 0.9'
34
+ spec.add_dependency 'ecoportal-api-v2', '>= 0.8.27', '< 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'
@@ -38,14 +38,14 @@ module Eco
38
38
  dir.newest_file(file: filename)
39
39
  end
40
40
 
41
- def file_content(filename)
41
+ def file_content(filename, mode: nil)
42
42
  file = dir.file(filename, should_exist: true)
43
43
  if !file
44
44
  logger.error("Can't read from file '#{filename}' because it does not exist.")
45
45
  return nil
46
46
  end
47
47
  logger.debug("Reading from file '#{file}'")
48
- File.read(file)
48
+ mode ? File.read(file, mode: mode) : File.read(file)
49
49
  end
50
50
 
51
51
  def load_json(filename)
@@ -65,8 +65,11 @@ module Eco
65
65
  # @param files [String, Array<String>] full path to remote file(s) to be downloaded
66
66
  # @param local_folder [String] local destination folder (`"."` if not specified)
67
67
  def download(files, local_folder: nil)
68
+ puts "Creating local files:"
68
69
  [files].flatten.compact.map do |fullname|
69
- dest_fullname = File.join(local_folder || ".", File.basename(fullname))
70
+ basename = windows_basename(fullname)
71
+ dest_fullname = File.join(local_folder || ".", basename)
72
+ puts " • #{dest_fullname}"
70
73
  sftp_session.download(fullname, dest_fullname)
71
74
  end.each do |dw|
72
75
  # run SSH event loop while dw.active?
@@ -76,6 +79,12 @@ module Eco
76
79
 
77
80
  private
78
81
 
82
+ def windows_basename(remote_fullname)
83
+ parts = remote_fullname.split(/[\\\/]/).map {|node| node.gsub(/[<>:\\\/\|?*]/, '_')}
84
+ local_fullname = File.join(*parts)
85
+ File.basename(local_fullname)
86
+ end
87
+
79
88
  def logger
80
89
  @enviro&.logger || ::Logger.new(IO::NULL)
81
90
  end
@@ -50,7 +50,7 @@ class Eco::API::UseCases::DefaultCases::Samples::Sftp < Eco::API::Common::Loader
50
50
  with_remote_files.tap do |files|
51
51
  unless files.empty?
52
52
  file_names = files.map {|file| to_remote_path(file.name)}
53
- puts "Getting the following files:"
53
+ puts "Getting the following files into the local folder '#{local_folder}':"
54
54
  puts file_names
55
55
  sftp.download(file_names, local_folder: local_folder)
56
56
  end
@@ -6,13 +6,20 @@ module Eco
6
6
  module Shortcuts
7
7
 
8
8
  # Offers multiple ways to compare two strings
9
- def same_string?(value1, value2, exact: false)
9
+ def same_string?(value1, value2, exact: false, mild: false)
10
10
  case
11
11
  when value1.is_a?(String) && value2.is_a?(String)
12
12
  if exact
13
13
  value1 == value2
14
14
  else
15
- value1.to_s.strip.downcase == value2.to_s.strip.downcase
15
+ v1 = value1.to_s.strip.downcase
16
+ v2 = value2.to_s.strip.downcase
17
+
18
+ if mild
19
+ v1 = v1.gsub(/[^a-z ]+/, ' ').gsub(/\s+/, ' ').strip
20
+ v2 = v2.gsub(/[^a-z ]+/, ' ').gsub(/\s+/, ' ').strip
21
+ end
22
+ v1 == v2
16
23
  end
17
24
  when value1.is_a?(Regexp) && value2.is_a?(String)
18
25
  value2 =~ value1
@@ -64,11 +71,31 @@ module Eco
64
71
  ref << "Page (#{obj.id}) (#{object_reference(obj.current_stage)})"
65
72
  when Ecoportal::API::V2::Page
66
73
  ref << "Page"
74
+ when Ecoportal::API::V2::Page::Section
75
+ ref << "Section '#{obj.heading || "(unnamed)"}'"
76
+ when Ecoportal::API::V2::Page::Component
77
+ ref << "Component '#{obj.label || "(unnamed of type '#{obj.type}')"}' in #{object_reference(obj.section)}"
78
+ when Ecoportal::API::V2::Page::Force
79
+ ref << "Force '#{obj.name}'"
80
+ when Ecoportal::API::V2::Page::Force::Binding
81
+ ref << "Binding '#{obj.name}' in #{object_reference(obj.force)}"
67
82
  end
68
83
  ref << " '#{obj.name}'" if obj.respond_to?(:name)
69
84
  end
70
85
  end
71
86
 
87
+ def to_i
88
+ Float(value).to_i
89
+ end
90
+
91
+ # https://stackoverflow.com/a/5661695/4352306
92
+ def is_number?(value)
93
+ begin
94
+ true if Float(value)
95
+ rescue ArgumentError => e
96
+ false
97
+ end
98
+ end
72
99
  end
73
100
  end
74
101
  end
@@ -29,7 +29,18 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
29
29
 
30
30
  protected
31
31
 
32
- def add_field(name, type, section, after: nil, before: nil, side: :left)
32
+ def add_field_by_doc(doc, section, after: nil, before: nil, side: :left)
33
+ unless section.is_a?(Ecoportal::API::V2::Page::Section)
34
+ raise "You need to specify a section for a new field. Given: #{section.class}"
35
+ end
36
+ target.components.add(doc: doc) do |field|
37
+ section.add_component(field, after: after, before: before, side: side)
38
+ end.tap do |field|
39
+ yield(field) if block_given?
40
+ end
41
+ end
42
+
43
+ def add_field(name, type, section, after: nil, before: nil, side: :left)
33
44
  unless section.is_a?(Ecoportal::API::V2::Page::Section)
34
45
  raise "You need to specify a section for a new field. Given: #{section.class}"
35
46
  end
@@ -92,7 +103,7 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
92
103
  if ooze_id = ooze && ooze.id
93
104
  exit_error "#{object_reference(ooze)} does not have stages!" unless ooze.stages?
94
105
  else
95
- exit_error "There's no target ooze to get retrieve stages from"
106
+ exit_error "There's no target ooze to retrieve stages from"
96
107
  end
97
108
 
98
109
  if stg = ooze.stages[id_name] || ooze.stages.get_by_name(id_name)
@@ -129,11 +140,15 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
129
140
  end
130
141
  end
131
142
  else
143
+ ooze.validate.tap do |validation|
144
+ logger.error(validation) if validation.is_a?(String)
145
+ end
132
146
  unless options.dig(:feedback, :only_stats)
133
147
  if patch = (patch_doc(ooze) || {})["page"]
134
148
  pp patch
135
149
  end
136
150
  end
151
+
137
152
  backup_patch!(ooze)
138
153
  exit(0) if dirty?(ooze) && dry_count > DRY_COUNT
139
154
  false
@@ -189,6 +204,4 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
189
204
  logger.error(msg)
190
205
  exit(1)
191
206
  end
192
-
193
-
194
207
  end
@@ -3,24 +3,26 @@ class Eco::API::UseCases::OozeSamples::OozeRunBaseCase < Eco::API::UseCases::Ooz
3
3
  name "ooze-run-base"
4
4
  type :other
5
5
 
6
- attr_reader :session, :options, :usecase
7
-
8
6
  SAVE_PATCH = "ooze_patch_update.json"
9
7
 
10
- def main(session, options, usecase, &block)
11
- raise "You need to inherit from this class and call super with a block" unless block
12
- @session = session; @options = options; @usecase = usecase
13
- process_ooze(&block)
14
- end
15
-
16
- def process_ooze(ooze = target)
17
- raise "You need to inherit from this class and call super with a block" unless block_given?
18
- super(ooze) do
19
- yield(ooze)
8
+ def main(session, options, usecase)
9
+ super(session, options, usecase) do
10
+ if method(:process_ooze).parameters.count == 0
11
+ ooze # retrieve ooze
12
+ process_ooze
13
+ else
14
+ process_ooze(ooze)
15
+ end
16
+ yield(target) if block_given?
20
17
  exit_if_no_changes!
18
+ update_ooze(target)
21
19
  end
22
20
  end
23
21
 
22
+ def process_ooze(page = target)
23
+ raise "You need to redefine this method"
24
+ end
25
+
24
26
  private
25
27
 
26
28
  def ooze
@@ -39,7 +39,8 @@ class Eco::API::UseCases::OozeSamples::RegisterUpdateCase < Eco::API::UseCases::
39
39
  msg += " • Duplicated search results #{dupped_search_oozes}\n"
40
40
  msg += " • Retrieved a total of #{retrieved_oozes}\n"
41
41
  msg += " • Could not get #{non_retrieved_oozes} oozes.\n"
42
- msg += " • Updated #{updated_oozes} oozes (failed update on #{failed_update_oozes} oozes).\n"
42
+ msg += " • Updated #{updated_oozes} oozes.\n"
43
+ msg += " - Failed update on #{failed_update_oozes} oozes.\n"
43
44
  logger.info(msg)
44
45
  end
45
46
 
@@ -72,7 +73,6 @@ class Eco::API::UseCases::OozeSamples::RegisterUpdateCase < Eco::API::UseCases::
72
73
  end
73
74
 
74
75
  if pending = queue_shift(page_result.id)
75
-
76
76
  if dirty?(pending)
77
77
  msg = "Inconsistent search results. "
78
78
  msg << "Launching update on '#{object_reference(pending)}' to be able to queue it back"
data/lib/eco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "2.0.53"
2
+ VERSION = "2.0.56"
3
3
  end
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.53
4
+ version: 2.0.56
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.26
139
+ version: 0.8.27
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.26
149
+ version: 0.8.27
150
150
  - - "<"
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0.9'