eco-helpers 2.6.3 → 2.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +95 -0
- data/CHANGELOG.md +135 -2
- data/Rakefile +13 -7
- data/eco-helpers.gemspec +3 -3
- data/lib/eco/api/common/loaders/base.rb +2 -2
- data/lib/eco/api/common/loaders/case_base.rb +1 -1
- data/lib/eco/api/common/loaders/config/workflow/mailer.rb +5 -5
- data/lib/eco/api/common/loaders/error_handler.rb +8 -5
- data/lib/eco/api/common/loaders/parser.rb +44 -22
- data/lib/eco/api/common/loaders/policy.rb +6 -4
- data/lib/eco/api/common/loaders/use_case.rb +13 -7
- data/lib/eco/api/common/people/base_parser.rb +0 -2
- data/lib/eco/api/common/people/default_parsers/boolean_parser.rb +0 -1
- data/lib/eco/api/common/people/default_parsers/csv_parser.rb +1 -1
- data/lib/eco/api/common/people/default_parsers/date_parser.rb +64 -12
- data/lib/eco/api/common/people/default_parsers/freemium_parser.rb +0 -1
- data/lib/eco/api/common/people/default_parsers/login_providers_parser.rb +13 -5
- data/lib/eco/api/common/people/default_parsers/multi_parser.rb +0 -1
- data/lib/eco/api/common/people/default_parsers/numeric_parser.rb +18 -5
- data/lib/eco/api/common/people/default_parsers/policy_groups_parser.rb +8 -8
- data/lib/eco/api/common/people/default_parsers/select_parser.rb +50 -26
- data/lib/eco/api/common/people/default_parsers/send_invites_parser.rb +6 -6
- data/lib/eco/api/common/people/default_parsers/xls_parser.rb +9 -12
- data/lib/eco/api/common/people/default_parsers.rb +1 -12
- data/lib/eco/api/common/people/entries.rb +13 -13
- data/lib/eco/api/common/people/entry_factory.rb +76 -45
- data/lib/eco/api/common/people/person_attribute_parser.rb +8 -12
- data/lib/eco/api/common/people/person_entry.rb +86 -75
- data/lib/eco/api/common/people/person_entry_attribute_mapper.rb +60 -44
- data/lib/eco/api/common/people/person_factory.rb +30 -22
- data/lib/eco/api/common/people/person_modifier.rb +11 -13
- data/lib/eco/api/common/people/person_parser.rb +101 -39
- data/lib/eco/api/common/people/supervisor_helpers.rb +25 -26
- data/lib/eco/api/common/session/base_session.rb +9 -9
- data/lib/eco/api/common/session/environment.rb +7 -5
- data/lib/eco/api/common/session/sftp.rb +59 -32
- data/lib/eco/api/common/version_patches/ecoportal_api/external_person.rb +10 -6
- data/lib/eco/api/common/version_patches/exception.rb +11 -13
- data/lib/eco/api/error.rb +32 -20
- data/lib/eco/api/microcases/set_supervisor.rb +0 -3
- data/lib/eco/api/organization/node_classifications.rb +82 -0
- data/lib/eco/api/organization/policy_groups.rb +4 -6
- data/lib/eco/api/organization/tag_tree.rb +169 -93
- data/lib/eco/api/organization.rb +1 -0
- data/lib/eco/api/session/batch/job.rb +1 -1
- data/lib/eco/api/session/config/tagtree.rb +41 -23
- data/lib/eco/api/session/config/workflow.rb +113 -88
- data/lib/eco/api/session/config.rb +6 -0
- data/lib/eco/api/session.rb +51 -29
- data/lib/eco/api/usecases/base_io.rb +28 -25
- data/lib/eco/api/usecases/default/locations/cli/tagtree_extract_cli.rb +7 -2
- data/lib/eco/api/usecases/default/locations/cli/tagtree_upload_cli.rb +21 -0
- data/lib/eco/api/usecases/default/locations/csv_to_tree_case.rb +3 -3
- data/lib/eco/api/usecases/default/locations/tagtree_extract_case.rb +54 -23
- data/lib/eco/api/usecases/default/locations/tagtree_upload_case.rb +87 -0
- data/lib/eco/api/usecases/default/locations.rb +1 -0
- data/lib/eco/api/usecases/default/people/analyse_people_case.rb +60 -56
- data/lib/eco/api/usecases/default/people/change_email_case.rb +8 -9
- data/lib/eco/api/usecases/default/people/clean_unknown_tags_case.rb +13 -11
- data/lib/eco/api/usecases/default/people/clear_abilities_case.rb +2 -2
- data/lib/eco/api/usecases/default/people/org_data_convert_case.rb +25 -27
- data/lib/eco/api/usecases/default/people/refresh_case.rb +2 -2
- data/lib/eco/api/usecases/default/people/reinvite_trans_case.rb +1 -1
- data/lib/eco/api/usecases/default/people/reinvite_trans_cli.rb +0 -1
- data/lib/eco/api/usecases/default/people/restore_db_case.rb +39 -34
- data/lib/eco/api/usecases/default/people/set_default_tag_case.rb +19 -15
- data/lib/eco/api/usecases/default/people/supers_cyclic_identify_case.rb +16 -12
- data/lib/eco/api/usecases/default_cases/hris_case.rb +17 -15
- data/lib/eco/api/usecases/default_cases/samples/sftp_case.rb +30 -16
- data/lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb +0 -2
- data/lib/eco/api/usecases/graphql/base.rb +5 -3
- data/lib/eco/api/usecases/graphql/helpers/base/case_env.rb +4 -1
- data/lib/eco/api/usecases/graphql/helpers/base/graphql_env.rb +14 -0
- data/lib/eco/api/usecases/graphql/helpers/base.rb +5 -4
- data/lib/eco/api/usecases/graphql/helpers/location/base/classifications_parser.rb +60 -0
- data/lib/eco/api/usecases/graphql/helpers/location/base/tree_tracking.rb +72 -0
- data/lib/eco/api/usecases/graphql/helpers/location/base.rb +25 -59
- data/lib/eco/api/usecases/graphql/helpers/location/command/diff/as_update.rb +59 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diff/compare.rb +49 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diff.rb +11 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/commandable.rb +46 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/diff_sortable/for_archive.rb +23 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/diff_sortable/for_unarchive.rb +65 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/diff_sortable.rb +49 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/sortable/relation_safe_sort.rb +119 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/sortable.rb +59 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages.rb +82 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs.rb +20 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/optimizations.rb +84 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/result.rb +4 -4
- data/lib/eco/api/usecases/graphql/helpers/location/command/results.rb +24 -12
- data/lib/eco/api/usecases/graphql/helpers/location/command.rb +21 -24
- data/lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_map.rb +1 -1
- data/lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_set.rb +10 -11
- data/lib/eco/api/usecases/graphql/helpers/location/tags_remap.rb +8 -9
- data/lib/eco/api/usecases/graphql/samples/location/command/dsl.rb +41 -12
- data/lib/eco/api/usecases/graphql/samples/location/command/results.rb +11 -80
- data/lib/eco/api/usecases/graphql/samples/location/command/service/tree_update.rb +89 -0
- data/lib/eco/api/usecases/graphql/samples/location/command/service.rb +6 -0
- data/lib/eco/api/usecases/graphql/samples/location/command/track_changed_ids.rb +89 -0
- data/lib/eco/api/usecases/graphql/samples/location/command.rb +3 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/base.rb +9 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/heading.rb +18 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/inputable.rb +53 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/parsing/classifications.rb +34 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/parsing/helpers.rb +28 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/parsing.rb +46 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible.rb +38 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff.rb +105 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/discarded.rb +16 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/input.rb +15 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/node_attr_maps.rb +22 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/parser.rb +45 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb +36 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/output.rb +56 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list.rb +41 -0
- data/lib/eco/api/usecases/graphql/samples/location/service.rb +8 -0
- data/lib/eco/api/usecases/graphql/samples/location.rb +1 -0
- data/lib/eco/api/usecases/graphql/utils/sftp.rb +96 -36
- data/lib/eco/api/usecases/ooze_cases/export_register_case.rb +8 -6
- data/lib/eco/api/usecases/ooze_samples/helpers/creatable.rb +4 -3
- data/lib/eco/api/usecases/ooze_samples/helpers/exportable_ooze.rb +39 -25
- data/lib/eco/api/usecases/ooze_samples/helpers/exportable_register.rb +13 -15
- data/lib/eco/api/usecases/ooze_samples/helpers/filters.rb +50 -21
- data/lib/eco/api/usecases/ooze_samples/helpers/ooze_handlers.rb +21 -11
- data/lib/eco/api/usecases/ooze_samples/helpers/rescuable.rb +2 -0
- data/lib/eco/api/usecases/ooze_samples/helpers/shortcuts.rb +49 -43
- data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +17 -19
- data/lib/eco/api/usecases/ooze_samples/register_export_case.rb +48 -43
- data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +34 -34
- data/lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb +8 -10
- data/lib/eco/api/usecases.rb +0 -1
- data/lib/eco/cli/config/use_cases.rb +31 -29
- data/lib/eco/cli_default/input_filters.rb +0 -5
- data/lib/eco/cli_default/people_filters.rb +4 -4
- data/lib/eco/cli_default/workflow.rb +13 -14
- data/lib/eco/csv/table.rb +34 -25
- data/lib/eco/data/hashes/array_diff.rb +24 -35
- data/lib/eco/data/hashes/diff_result/meta.rb +131 -0
- data/lib/eco/data/hashes/diff_result.rb +65 -57
- data/lib/eco/data/hashes/sanke_camel_indifferent_access.rb +278 -0
- data/lib/eco/data/hashes.rb +1 -1
- data/lib/eco/data/locations/convert.rb +1 -1
- data/lib/eco/data/locations/node_base/csv_convert.rb +19 -9
- data/lib/eco/data/locations/node_base/parsing.rb +4 -2
- data/lib/eco/data/locations/node_base/treeify.rb +149 -132
- data/lib/eco/data/locations/node_base.rb +15 -4
- data/lib/eco/data/locations/node_diff/accessors.rb +13 -5
- data/lib/eco/data/locations/node_diff/nodes_diff/clustered_treeify.rb +101 -0
- data/lib/eco/data/locations/node_diff/nodes_diff/diffs_tree.rb +99 -0
- data/lib/eco/data/locations/node_diff/{selectors.rb → nodes_diff/selectors.rb} +1 -1
- data/lib/eco/data/locations/node_diff/nodes_diff.rb +50 -35
- data/lib/eco/data/locations/node_diff.rb +45 -17
- data/lib/eco/data/locations/node_level/parsing.rb +15 -21
- data/lib/eco/data/locations/node_level.rb +66 -22
- data/lib/eco/data/locations/node_plain/parsing.rb +1 -1
- data/lib/eco/data/locations/node_plain.rb +60 -7
- data/lib/eco/data/strings/camel_case.rb +35 -0
- data/lib/eco/data/strings/snake_case.rb +18 -0
- data/lib/eco/data/strings.rb +8 -0
- data/lib/eco/data.rb +1 -0
- data/lib/eco/language/methods/call_detector.rb +11 -0
- data/lib/eco/language/methods/dsl_able.rb +7 -1
- data/lib/eco/language/methods.rb +2 -1
- data/lib/eco/language/models/collection.rb +23 -25
- data/lib/eco/language/models/parser_serializer.rb +24 -5
- data/lib/eco/version.rb +1 -1
- data/lib/eco-helpers.rb +0 -1
- metadata +54 -9
- data/lib/eco/data/hashes/diff_meta.rb +0 -52
@@ -0,0 +1,15 @@
|
|
1
|
+
module Eco::API::UseCases::GraphQL::Samples::Location::Service
|
2
|
+
module TreeToList
|
3
|
+
module Converter
|
4
|
+
module Input
|
5
|
+
include Eco::API::UseCases::GraphQL::Samples::Location::DSL
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def input_tagtree
|
10
|
+
@input_tagtree ||= live_tree
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/node_attr_maps.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Eco::API::UseCases::GraphQL::Samples::Location::Service
|
2
|
+
module TreeToList
|
3
|
+
module Converter
|
4
|
+
module NodeAttrMaps
|
5
|
+
# Basic mappints to create NodeDiff
|
6
|
+
NODE_ATTR_MAPS = {
|
7
|
+
'id' => 'nodeId',
|
8
|
+
'parent_id' => 'parentId',
|
9
|
+
'parent_name' => 'parentName',
|
10
|
+
'archived_token' => 'archivedToken',
|
11
|
+
'level' => 'level_reference'
|
12
|
+
}.freeze
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def node_attr_maps
|
17
|
+
self.class::NODE_ATTR_MAPS
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Eco::API::UseCases::GraphQL::Samples::Location::Service
|
2
|
+
module TreeToList
|
3
|
+
module Converter
|
4
|
+
module Parser
|
5
|
+
private
|
6
|
+
|
7
|
+
# Adds up to the generic_node_parser
|
8
|
+
# def custom_node_parser(node_hash)
|
9
|
+
# node_hash.each do |key, val|
|
10
|
+
# end
|
11
|
+
# end
|
12
|
+
|
13
|
+
def node_parser_block
|
14
|
+
return @node_parser_block if instance_variable_defined?(:@node_parser_block)
|
15
|
+
custom_before = custom_node_parser_before_block
|
16
|
+
custom_after = custom_node_parser_block
|
17
|
+
@node_parser_block = proc do |node_hash|
|
18
|
+
node_hash.tap do
|
19
|
+
custom_before&.call(node_hash)
|
20
|
+
default_node_parse(node_hash)
|
21
|
+
custom_after&.call(node_hash)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Grabs the custom node parser that runs after the generic one
|
27
|
+
def custom_node_parser_block
|
28
|
+
return nil unless respond_to?(:custom_node_parser, true)
|
29
|
+
method(:custom_node_parser)
|
30
|
+
end
|
31
|
+
|
32
|
+
def custom_node_parser_before_block
|
33
|
+
return nil unless respond_to?(:custom_node_parser_before, true)
|
34
|
+
method(:custom_node_parser_before)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Generic parsing
|
38
|
+
def default_node_parse(node_hash)
|
39
|
+
class_ids = to_classification_ids(node_hash['classifications'])
|
40
|
+
node_hash['classifications'] = class_ids
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative 'converter/parser'
|
2
|
+
require_relative 'converter/input'
|
3
|
+
require_relative 'converter/node_attr_maps'
|
4
|
+
require_relative 'converter/discarded'
|
5
|
+
|
6
|
+
module Eco::API::UseCases::GraphQL::Samples::Location::Service
|
7
|
+
module TreeToList
|
8
|
+
module Converter
|
9
|
+
include Parser
|
10
|
+
include Input
|
11
|
+
include NodeAttrMaps
|
12
|
+
include Discarded
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
# Converter. Transforms an org tagtree to a list of hash nodes
|
17
|
+
# @note it ensures `DISCARDED_NODES` are excluded
|
18
|
+
# @return [Array<Hash>] list of hash nodes
|
19
|
+
def as_nodes_json(tree = input_tagtree)
|
20
|
+
tree.reject do |node|
|
21
|
+
discarded?(node.id)
|
22
|
+
end.each_with_object([]) do |node, list|
|
23
|
+
list << node.as_json(include_children: false).transform_keys do |key|
|
24
|
+
next key unless node_attr_maps.key?(key)
|
25
|
+
node_attr_maps[key]
|
26
|
+
end.tap do |node_hash|
|
27
|
+
node_parser_block&.call(node_hash)
|
28
|
+
yield(node_hash) if block_given?
|
29
|
+
end
|
30
|
+
end.tap do |list|
|
31
|
+
list.each(&node_parser_block)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Eco::API::UseCases::GraphQL::Samples::Location::Service
|
2
|
+
module TreeToList
|
3
|
+
module Output
|
4
|
+
OUT_FOLDER = 'sftp'.freeze
|
5
|
+
OUT_TIME_FORMAT = '%Y%m%dT%H%M%S'.freeze
|
6
|
+
OUT_FILENAME = 'Location_Nodes.csv'.freeze
|
7
|
+
OUT_HEADER = %w[
|
8
|
+
nodeId
|
9
|
+
name
|
10
|
+
parentId
|
11
|
+
parentName
|
12
|
+
archived
|
13
|
+
archivedToken
|
14
|
+
weight
|
15
|
+
level_reference
|
16
|
+
].freeze
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def generate_live_nodes_file(nodes_list)
|
21
|
+
return unless generate_live_nodes_file?
|
22
|
+
CSV.open(output_filename, "w") do |csv|
|
23
|
+
csv << output_header
|
24
|
+
nodes_list do |item|
|
25
|
+
csv << item.values_at(*output_header)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
log(:info) { "Created file: #{output_filename}" }
|
29
|
+
end
|
30
|
+
|
31
|
+
def output_header
|
32
|
+
self.class::OUT_HEADER
|
33
|
+
end
|
34
|
+
|
35
|
+
def generate_live_nodes_file?
|
36
|
+
true
|
37
|
+
end
|
38
|
+
|
39
|
+
def output_filename
|
40
|
+
@output_filename ||= File.join(output_folder, "#{timestamp}_#{output_file}")
|
41
|
+
end
|
42
|
+
|
43
|
+
def output_folder
|
44
|
+
"#{config.active_enviro}/#{self.class::OUT_FOLDER}"
|
45
|
+
end
|
46
|
+
|
47
|
+
def output_file
|
48
|
+
options.dig(:output, :file) || self.class::OUT_FILENAME
|
49
|
+
end
|
50
|
+
|
51
|
+
def timestamp(date = Time.now)
|
52
|
+
date.strftime(self.class::OUT_TIME_FORMAT)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Eco::API::UseCases::GraphQL::Samples
|
2
|
+
module Location::Service
|
3
|
+
# Service to transform (CONVERT or PARSE) an input locations structure into a list
|
4
|
+
# of hash nodes.
|
5
|
+
# @note it can have multiple usages
|
6
|
+
# 1. Live locations tree structure into a nodes list file (nodeId, parendId, name,...)
|
7
|
+
# 2. A locations tree built from an input csv into a nodes list hash
|
8
|
+
# 3. Change the keys of the hash nodes
|
9
|
+
# 4. Parse the values
|
10
|
+
# @note this use case can be inherited from to provision **parsed** input to other
|
11
|
+
# use cases.
|
12
|
+
# @note it allows to define `custom_node_parser` and `custom_node_parser_after`
|
13
|
+
# methods (param: `node_hash`), to allow custom parsing.
|
14
|
+
# - It has a generic parser that validates the `classifications`
|
15
|
+
# As this format allows to easily compare what has changed in the locations structure.
|
16
|
+
# @example
|
17
|
+
# class Custom::UseCase::TagtreeToList < Eco::API::UseCases::GraphQL::Samples::Location
|
18
|
+
# name 'tagtree-to-list'
|
19
|
+
# type :other
|
20
|
+
#
|
21
|
+
# include Eco::API::UseCases::GraphQL::Samples::Location::Service::TreeToList
|
22
|
+
#
|
23
|
+
# end
|
24
|
+
module TreeToList
|
25
|
+
include Eco::API::UseCases::GraphQL::Samples::Location::DSL
|
26
|
+
|
27
|
+
require_relative 'tree_to_list/output'
|
28
|
+
require_relative 'tree_to_list/converter'
|
29
|
+
|
30
|
+
include Output
|
31
|
+
include Converter
|
32
|
+
|
33
|
+
def process
|
34
|
+
as_nodes_json(input_tagtree).tap do |list|
|
35
|
+
next generate_live_nodes_file(list) unless list.empty?
|
36
|
+
log(:error) { "There are no location nodes!" }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -2,61 +2,121 @@ module Eco::API::UseCases::GraphQL::Utils
|
|
2
2
|
module Sftp
|
3
3
|
include Eco::API::UseCases::GraphQL::Helpers::Base::CaseEnv
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
"#{sftp_config.remote_folder}/#{subfolder || ''}"
|
5
|
+
def upload(local_file, subfolder: remote_subfolder, gid: sftp_group_id)
|
6
|
+
sftp_session.upload(
|
7
|
+
local_file,
|
8
|
+
remote_folder: remote_folder(subfolder),
|
9
|
+
gid: gid
|
10
|
+
)
|
12
11
|
end
|
12
|
+
alias_method :sftp_upload, :upload
|
13
13
|
|
14
14
|
def sftp_group_id
|
15
15
|
if self.class.const_defined?(:SFTP_GROUP)
|
16
|
-
self.class.const_get(:
|
17
|
-
elsif group_id = options.dig(:sftp, :group)
|
16
|
+
self.class.const_get(:SFTP_GROUP)
|
17
|
+
elsif (group_id = options.dig(:sftp, :group))
|
18
18
|
group_id
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
22
|
+
def sftp_download_files(subfolder: remote_subfolder, pattern: nil, local_folder: self.local_folder)
|
23
|
+
with_remote_files(subfolder: subfolder, pattern: pattern).tap do |files|
|
24
|
+
next if files.empty?
|
25
|
+
file_names = files.map {|file| to_remote_path(file.name, subfolder: subfolder)}
|
26
|
+
|
27
|
+
log(:info) {
|
28
|
+
msg = "Getting the following files into the local folder '#{local_folder}':\n"
|
29
|
+
msg << " • "
|
30
|
+
msg << files_names.join("\n • ")
|
31
|
+
msg
|
32
|
+
}
|
33
|
+
|
34
|
+
sftp.download(file_names, local_folder: local_folder)
|
29
35
|
end
|
30
|
-
logger.info("Uploaded '#{local_file}' (#{res})")
|
31
36
|
end
|
32
37
|
|
33
|
-
def
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
file
|
39
|
-
end
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
38
|
+
def sftp_move_file(source, dest)
|
39
|
+
sftp.move(source, dest, 0x0001) do |response|
|
40
|
+
if response.ok?
|
41
|
+
log(:info) { "#{source}\n -to-> #{dest}" }
|
42
|
+
else
|
43
|
+
log(:info) { "Could not move file #{source}" }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def ensure_remote_empty(subfolder: remote_subfolder, pattern: nil)
|
49
|
+
files = with_remote_files(subfolder: subfolder, pattern: pattern)
|
50
|
+
return if files.empty?
|
51
|
+
|
52
|
+
msg = "There are still files in the remote folder that will be deleted: '#{subfolder}':\n"
|
53
|
+
msg << " • "
|
54
|
+
str = files.map(&:longname).join("\n • ")
|
55
|
+
str << "\n"
|
56
|
+
msg << str
|
57
|
+
|
58
|
+
session.prompt_user(
|
59
|
+
"Do you want to proceed to delete? (Y/n):",
|
60
|
+
explanation: msg,
|
61
|
+
default: "Y",
|
62
|
+
timeout: 3
|
63
|
+
) do |response|
|
64
|
+
next unless response.upcase.start_with?("Y")
|
65
|
+
|
66
|
+
files.each do |file|
|
67
|
+
remote_full_path = to_remote_path(file.name, subfolder: subfolder)
|
68
|
+
res = sftp_session.remove(remote_full_path)
|
69
|
+
log(:info) {
|
70
|
+
"Deleted remote file: '#{remote_full_path}' (#{res})"
|
71
|
+
}
|
48
72
|
end
|
49
73
|
end
|
50
74
|
end
|
51
75
|
|
52
|
-
|
53
|
-
|
76
|
+
# @param subfolder [String] the subfolder.
|
77
|
+
def with_remote_files(subfolder: remote_subfolder, pattern: nil)
|
78
|
+
sftp.files(remote_folder(subfolder), pattern: pattern).each do |remote_file|
|
54
79
|
yield(remote_file) if block_given?
|
55
80
|
end
|
81
|
+
rescue ArgumentError
|
82
|
+
raise
|
83
|
+
rescue ::Net::SFTP::StatusException => err
|
84
|
+
log(:error) {
|
85
|
+
msg = "(#{self.class}) There was an error trying to access "
|
86
|
+
msg << "the remote folder '#{subfolder}': #{err}"
|
87
|
+
msg
|
88
|
+
}
|
89
|
+
[]
|
90
|
+
end
|
91
|
+
|
92
|
+
def to_remote_path(file, subfolder: remote_subfolder)
|
93
|
+
[remote_folder(subfolder), file].join('/')
|
94
|
+
end
|
95
|
+
|
96
|
+
def remote_subfolder
|
97
|
+
if (remote_dir = options.dig(:sftp, :remote_subfolder))
|
98
|
+
remote_dir
|
99
|
+
elsif self.class.const_defined?(:REMOTE_FOLDER)
|
100
|
+
self.class::REMOTE_FOLDER
|
101
|
+
end
|
56
102
|
end
|
57
103
|
|
58
|
-
def
|
59
|
-
|
104
|
+
def remote_folder(subfolder = remote_subfolder)
|
105
|
+
[sftp_env_base_path, subfolder].compact.join('/')
|
106
|
+
end
|
107
|
+
|
108
|
+
def sftp_env_base_path
|
109
|
+
sftp_config.remote_folder
|
110
|
+
end
|
111
|
+
|
112
|
+
def local_folder
|
113
|
+
if (local_dir = options.dig(:sftp, :local_folder))
|
114
|
+
local_dir
|
115
|
+
elsif self.class.const_defined?(:LOCAL_FOLDER)
|
116
|
+
self.class::LOCAL_FOLDER
|
117
|
+
else
|
118
|
+
"."
|
119
|
+
end
|
60
120
|
end
|
61
121
|
|
62
122
|
def sftp_config
|
@@ -23,8 +23,8 @@ class Eco::API::UseCases::OozeCases::ExportRegisterCase < Eco::API::UseCases::Oo
|
|
23
23
|
|
24
24
|
def filters
|
25
25
|
[].tap do |fltrs|
|
26
|
-
[
|
27
|
-
[
|
26
|
+
%i[any all].each {|mode| fltrs << build_tags_filter(mode)}
|
27
|
+
%i[created_at updated_at].each {|key| fltrs << build_range_filter(key)}
|
28
28
|
end.compact
|
29
29
|
end
|
30
30
|
|
@@ -45,8 +45,10 @@ class Eco::API::UseCases::OozeCases::ExportRegisterCase < Eco::API::UseCases::Oo
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def build_range_filter(key = :update_at)
|
48
|
-
from = from_date(key)
|
48
|
+
from = from_date(key)
|
49
|
+
to = to_date(key)
|
49
50
|
return nil unless from || to
|
51
|
+
|
50
52
|
date_range_filter(from: from, to: to, key: key)
|
51
53
|
end
|
52
54
|
|
@@ -64,9 +66,9 @@ class Eco::API::UseCases::OozeCases::ExportRegisterCase < Eco::API::UseCases::Oo
|
|
64
66
|
|
65
67
|
def export_options
|
66
68
|
@export_options ||= {
|
67
|
-
delimiter:
|
68
|
-
only_indexed:
|
69
|
-
only_labeled:
|
69
|
+
delimiter: options_delimiter,
|
70
|
+
only_indexed: include_deindexed?,
|
71
|
+
only_labeled: include_unnamed?,
|
70
72
|
only_with_ref: include_unhashed?
|
71
73
|
}
|
72
74
|
end
|
@@ -13,9 +13,9 @@ module Eco
|
|
13
13
|
drafting_entry(template_id) do |draft|
|
14
14
|
yield(draft) if block_given?
|
15
15
|
|
16
|
-
if page_id = create_entry(draft, reference: draft_reference)
|
16
|
+
if (page_id = create_entry(draft, reference: draft_reference))
|
17
17
|
log(:info) { "Page '#{page_id}' created successfully -- #{draft_reference}" }
|
18
|
-
elsif options
|
18
|
+
elsif options[:dry_run]
|
19
19
|
log(:info) { "Simulated launch for #{draft_reference}" }
|
20
20
|
end
|
21
21
|
end
|
@@ -32,7 +32,7 @@ module Eco
|
|
32
32
|
# Does the actual creation of the entry
|
33
33
|
def create_entry(draft, reference: "new entry from #{draft&.template_id}")
|
34
34
|
with_rescue(reference) do
|
35
|
-
if result = create_ooze(draft, template_id: draft.template_id)
|
35
|
+
if (result = create_ooze(draft, template_id: draft.template_id))
|
36
36
|
return result.page_id
|
37
37
|
end
|
38
38
|
end
|
@@ -48,6 +48,7 @@ module Eco
|
|
48
48
|
|
49
49
|
def validate_base_type!(base)
|
50
50
|
return super if defined?(super)
|
51
|
+
|
51
52
|
msg = "#{self} can only be included in Eco::API::UseCases::OozeSamples::RegisterUpdateCase"
|
52
53
|
msg << "\nCan't be included in #{base}"
|
53
54
|
raise LoadError, msg unless base <= Eco::API::UseCases::OozeSamples::RegisterUpdateCase
|
@@ -5,18 +5,23 @@ module Eco
|
|
5
5
|
module Helpers
|
6
6
|
# Class to ease the export process
|
7
7
|
class ExportableOoze
|
8
|
-
MERGE_DELIMITER = "#:#"
|
9
|
-
|
10
|
-
|
11
|
-
"
|
12
|
-
"
|
13
|
-
"
|
14
|
-
"
|
15
|
-
"time_zone" => "Time Zone",
|
8
|
+
MERGE_DELIMITER = "#:#".freeze
|
9
|
+
META_FIELDS = {
|
10
|
+
"id" => "Internal ID",
|
11
|
+
"uid" => "Unique ID",
|
12
|
+
"name" => "Name of Page",
|
13
|
+
"state" => "State of Page",
|
14
|
+
"time_zone" => "Time Zone",
|
16
15
|
"created_at" => "Page Created",
|
17
16
|
"updated_at" => "Last updated",
|
18
|
-
"tags"
|
19
|
-
}
|
17
|
+
"tags" => "Location Tags"
|
18
|
+
}.freeze
|
19
|
+
DEFAULT_OPTIONS = {
|
20
|
+
delimiter: "\n",
|
21
|
+
only_indexed: true,
|
22
|
+
only_labeled: true,
|
23
|
+
only_with_ref: true
|
24
|
+
}.freeze
|
20
25
|
|
21
26
|
class << self
|
22
27
|
def label?(field)
|
@@ -24,9 +29,9 @@ module Eco
|
|
24
29
|
end
|
25
30
|
|
26
31
|
def label(field, default: nil)
|
27
|
-
value
|
32
|
+
value = nil
|
28
33
|
value ||= field.label.to_s.strip if field.respond_to?(:label)
|
29
|
-
value
|
34
|
+
value = nil unless value && !value.empty?
|
30
35
|
return value if value || !default
|
31
36
|
default || "Unnamed field:"
|
32
37
|
end
|
@@ -42,8 +47,10 @@ module Eco
|
|
42
47
|
|
43
48
|
def key_to_ref(str)
|
44
49
|
return str unless str.include?(MERGE_DELIMITER)
|
50
|
+
|
45
51
|
ref = str.split(MERGE_DELIMITER).first
|
46
|
-
ref.to_s.strip.empty
|
52
|
+
return ref unless ref.to_s.strip.empty?
|
53
|
+
nil
|
47
54
|
end
|
48
55
|
|
49
56
|
def indexed?(field)
|
@@ -65,14 +72,11 @@ module Eco
|
|
65
72
|
attr_reader :options
|
66
73
|
|
67
74
|
def initialize(ooze, **options)
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
only_labeled: true,
|
74
|
-
only_with_ref: true
|
75
|
-
})
|
75
|
+
msg = "Expecting Ecoportal::API::V2::Page. Given: #{ooze.class}"
|
76
|
+
raise msg unless ooze.is_a?(Ecoportal::API::V2::Page)
|
77
|
+
|
78
|
+
@ooze = ooze
|
79
|
+
@options = DEFAULT_OPTIONS.merge(options)
|
76
80
|
end
|
77
81
|
|
78
82
|
def delimiter
|
@@ -92,8 +96,17 @@ module Eco
|
|
92
96
|
meta_fields.tap do |data|
|
93
97
|
with_field_section_pairs do |field, section|
|
94
98
|
next unless export?(field)
|
95
|
-
|
96
|
-
|
99
|
+
|
100
|
+
key = self.class.key_ref_label(
|
101
|
+
field,
|
102
|
+
default: alternative_label(field, section)
|
103
|
+
)
|
104
|
+
data[key] = merge_values(
|
105
|
+
data[key],
|
106
|
+
to_value(field),
|
107
|
+
klass: field.class,
|
108
|
+
delimiter: delimiter
|
109
|
+
)
|
97
110
|
end
|
98
111
|
end
|
99
112
|
end
|
@@ -109,6 +122,7 @@ module Eco
|
|
109
122
|
sections = []
|
110
123
|
ordered_sections.each_with_object([]) do |section, out|
|
111
124
|
next if sections.include?(section)
|
125
|
+
|
112
126
|
sections << section
|
113
127
|
section.components.each do |field|
|
114
128
|
out << [field, section]
|
@@ -140,8 +154,8 @@ module Eco
|
|
140
154
|
def export?(field, **opts)
|
141
155
|
opts = options.merge(opts)
|
142
156
|
return false unless field.respond_to?(:to_s)
|
143
|
-
return false if opts[:only_indexed]
|
144
|
-
return false if opts[:only_labeled]
|
157
|
+
return false if opts[:only_indexed] && !self.class.indexed?(field)
|
158
|
+
return false if opts[:only_labeled] && !self.class.label?(field)
|
145
159
|
return false if opts[:only_with_ref] && !self.class.with_ref?(field)
|
146
160
|
true
|
147
161
|
end
|
@@ -5,7 +5,6 @@ module Eco
|
|
5
5
|
module Helpers
|
6
6
|
# Class to ease the export process
|
7
7
|
class ExportableRegister
|
8
|
-
|
9
8
|
attr_reader :options
|
10
9
|
|
11
10
|
include Eco::API::UseCases::OozeSamples::Helpers::OozeHandlers
|
@@ -13,17 +12,17 @@ module Eco
|
|
13
12
|
|
14
13
|
def initialize(**options)
|
15
14
|
@options = options.merge({
|
16
|
-
delimiter:
|
17
|
-
only_indexed:
|
18
|
-
only_labeled:
|
15
|
+
delimiter: "\n",
|
16
|
+
only_indexed: true,
|
17
|
+
only_labeled: true,
|
19
18
|
only_with_ref: true
|
20
19
|
})
|
21
20
|
end
|
22
21
|
|
23
22
|
def add_ooze(ooze)
|
24
|
-
ooz
|
25
|
-
data
|
26
|
-
@typed_header
|
23
|
+
ooz = ExportableOoze.new(ooze, **options)
|
24
|
+
data = ooz.key_typed_data
|
25
|
+
@typed_header = merge_arrays(data.keys, typed_header)
|
27
26
|
key_typed_data << data
|
28
27
|
end
|
29
28
|
|
@@ -32,19 +31,18 @@ module Eco
|
|
32
31
|
end
|
33
32
|
|
34
33
|
def each(as_values: true, as_row: false, &block)
|
35
|
-
return to_enum(:each, as_row: as_row) unless block
|
34
|
+
return to_enum(:each, as_values: as_values, as_row: as_row) unless block
|
35
|
+
|
36
36
|
key_typed_data.each do |ooze_data|
|
37
37
|
values = ooze_data.values_at(*typed_header)
|
38
|
-
|
39
|
-
|
38
|
+
|
39
|
+
if as_values
|
40
40
|
values
|
41
|
-
|
41
|
+
elsif as_row
|
42
42
|
::CSV::Row.new(values, header)
|
43
43
|
else
|
44
44
|
header.zip(values)
|
45
|
-
end.tap
|
46
|
-
yield(out)
|
47
|
-
end
|
45
|
+
end.tap(&block)
|
48
46
|
end
|
49
47
|
end
|
50
48
|
|
@@ -62,7 +60,7 @@ module Eco
|
|
62
60
|
end
|
63
61
|
|
64
62
|
def key_typed_data
|
65
|
-
@typed_keyed_data ||= []
|
63
|
+
@typed_keyed_data ||= [] # rubocop:disable Naming/MemoizedInstanceVariableName
|
66
64
|
end
|
67
65
|
end
|
68
66
|
end
|