Class: Eco::API::UseCases::Default::Locations::TagtreeUpload
- Inherits:
-
GraphQL::Samples::Location::Command
- Object
- Common::Loaders::Base
- Common::Loaders::CaseBase
- Common::Loaders::UseCase
- GraphQL::Base
- GraphQL::Samples::Location
- GraphQL::Samples::Location::Command
- Eco::API::UseCases::Default::Locations::TagtreeUpload
- Defined in:
- lib/eco/api/usecases/default/locations/tagtree_upload_case.rb,
lib/eco/api/usecases/default/locations/cli/tagtree_upload_cli.rb
Defined Under Namespace
Classes: Cli
Constant Summary collapse
- COMMANDS_PER_PAGE =
45
- TOP_ID =
nil
Constants included from GraphQL::Samples::Location::Command::TrackChangedIds
GraphQL::Samples::Location::Command::TrackChangedIds::REMAP_LOC_IDS_FILENAME, GraphQL::Samples::Location::Command::TrackChangedIds::REMAP_LOC_IDS_FOLDER
Constants included from GraphQL::Helpers::Location::Command::Optimizations
GraphQL::Helpers::Location::Command::Optimizations::DEFAULT_COMMANDS_PER_PAGE, GraphQL::Helpers::Location::Command::Optimizations::DEFAULT_FORCE_CONTINUE
Constants included from GraphQL::Helpers::Location::Base::TreeTracking
GraphQL::Helpers::Location::Base::TreeTracking::TAGTREE_BACKUP
Instance Attribute Summary
Attributes included from GraphQL::Samples::Location::Command::Results
Attributes included from Language::AuxiliarLogger
Attributes included from GraphQL::Samples::Location::Command::TrackChangedIds
Attributes included from GraphQL::Helpers::Location::Base::TreeTracking
Instance Method Summary collapse
- #input_csv ⇒ Object
- #input_file ⇒ Object
- #input_tree ⇒ Object
-
#inputs(force_continue: force_continue?) ) ⇒ Object
We only define the
:insert
stage. - #insert_command(node, pid: nil) ⇒ Object
- #insert_commands(tree = input_tree, pid: nil) ⇒ Object
- #top_id ⇒ Object
- #top_id?(node_id = nil) ⇒ Boolean
- #track_current_tree? ⇒ Boolean
- #tree_json ⇒ Object
Methods included from GraphQL::Samples::Location::Command::DSL
Methods included from GraphQL::Samples::Location::Command::Results
#page_errors?, #request_results_class, #rescued, #results
Methods included from Language::AuxiliarLogger
Methods included from GraphQL::Samples::Location::Command::TrackChangedIds
#close_handling_tags_remap_csv, #generate_tags_remap_csv, #tags_remap_class, #tags_remap_csv_full_filename, #tags_remap_table, #timestamp_file, #update_tags_remap_table
Methods included from GraphQL::Helpers::Location::Command
#apply_commands, #input, #sliced_batches, #with_sliced_input
Methods included from GraphQL::Helpers::Location::Command::Optimizations
#commands_payload_without_structure_block, #commands_per_page, #default_tree_tracking_mode, #force_continue?, #scope_commands_block
Methods included from GraphQL::Helpers::Location::Base
#live_tree, #session_live_tree, #tagtree_id, #target_structure_id, #target_structure_id_const
Methods included from GraphQL::Helpers::Location::Base::TreeTracking
#backup_tree, #track_current_tree
Methods inherited from GraphQL::Samples::Location
Methods inherited from GraphQL::Base
Methods included from Language::Methods::CallDetector
Methods inherited from Common::Loaders::UseCase
cli, cli!, #cli_apply!, #initialize, #main, type, #type
Methods inherited from Common::Loaders::CaseBase
Methods inherited from Common::Loaders::Base
<=>, created_at, #initialize, set_created_at!
Methods included from Common::ClassHelpers
#class_resolver, #descendants, #descendants?, #inheritable_attrs, #inheritable_class_vars, #inherited, #instance_variable_name, #new_class, #resolve_class, #to_constant
Constructor Details
This class inherits a constructor from Eco::API::Common::Loaders::UseCase
Instance Method Details
#input_csv ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/eco/api/usecases/default/locations/tagtree_upload_case.rb', line 76 def input_csv @input_csv ||= csv_from(input_file).tap do |table| log(:info) { "#{table.count} data rows loaded from #{input_file}" } end end |
#input_file ⇒ Object
84 85 86 |
# File 'lib/eco/api/usecases/default/locations/tagtree_upload_case.rb', line 84 def input_file @input_file ||= .dig(:source, :file) end |
#input_tree ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/eco/api/usecases/default/locations/tagtree_upload_case.rb', line 64 def input_tree @input_tree ||= Eco::API::Organization::TagTree.new(tree_json).tap do |tree| log(:info) { "Loaded input locations structure (#{tree.count} nodes)" } end end |
#inputs(force_continue: force_continue?) ) ⇒ Object
We only define the :insert
stage
15 16 17 18 19 20 21 |
# File 'lib/eco/api/usecases/default/locations/tagtree_upload_case.rb', line 15 def inputs(force_continue: force_continue?) {}.tap do |stages| stages[:insert] = input(insert_commands, force_continue: force_continue) end.each do |stage, input| yield(input, stage) if block_given? end end |
#insert_command(node, pid: nil) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/eco/api/usecases/default/locations/tagtree_upload_case.rb', line 38 def insert_command(node, pid: nil) { insert: { nodeId: node.id, name: node.name, parentId: pid }.tap do |node_hash| classification_ids = to_classification_ids(node.classifications) next unless classification_ids.any? node_hash.merge!({ classificationIds: node.classifications.dup }) end } end |
#insert_commands(tree = input_tree, pid: nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/eco/api/usecases/default/locations/tagtree_upload_case.rb', line 23 def insert_commands(tree = input_tree, pid: nil) [].tap do |comms| unless tree.top? pid = top_id if top_id? && pid.nil? comms << insert_command(tree, pid: pid) unless top_id?(tree.id) pid = tree.id end tree.nodes.map do |node| insert_commands(node, pid: pid) end.flatten(1).tap do |subs| comms.concat(subs) end end end |
#top_id ⇒ Object
60 61 62 |
# File 'lib/eco/api/usecases/default/locations/tagtree_upload_case.rb', line 60 def top_id .dig(:input, :top_id) || self.class::TOP_ID end |
#top_id?(node_id = nil) ⇒ Boolean
55 56 57 58 |
# File 'lib/eco/api/usecases/default/locations/tagtree_upload_case.rb', line 55 def top_id?(node_id = nil) return top_id.is_a?(String) if node_id.nil? node_id == top_id end |
#track_current_tree? ⇒ Boolean
10 11 12 |
# File 'lib/eco/api/usecases/default/locations/tagtree_upload_case.rb', line 10 def track_current_tree? false end |
#tree_json ⇒ Object
72 73 74 |
# File 'lib/eco/api/usecases/default/locations/tagtree_upload_case.rb', line 72 def tree_json hash_tree(input_csv) end |