module Eco::API::UseCases::GraphQL::Samples module Location::Service # Service to spot the differences between an input file and a locations tree. # @example # class Custom::UseCase::TagtreeDiff < Eco::API::UseCases::GraphQL::Samples::Location # name 'tagtree-diff' # type :other # require_relative 'cli/10_tagtree_diff_cli' # include Eco::API::UseCases::GraphQL::Samples::Location::Service::TreeDiff # IN_FILENAME = /requested_tree\.csv/.freeze # IN_FOLDER = 'sftp'.freeze # HEADER_MAPS = { # 'Code' => 'id', # 'Description' => 'name', # 'ParentCode' => 'parent_id', # 'IsActive' => 'active', # 'LevelDescription' => 'classifications' # }.freeze # CLASSIFICATION_MAPS = { # 'Directorate' => 'agency', # 'Subsection' => 'sub-section', # 'WorkUnit' => 'work-unit' # }.freeze # # def process # compare # end # # private # # def custom_input_csv_transform(csv) # csv.add_column('archived') # end # # def custom_input_row_transform(row) # row['archived'] = !as_boolean(row['active']) # end # end module TreeDiff include Eco::API::UseCases::GraphQL::Samples::Location::Service::TreeToList require_relative 'tree_diff/convertible' include Convertible def process compare end def compare comparer.tap do |cmp| puts comparer.diffs_details if print_diff_details? && cmp.diffs? log(:info) { cmp.diffs_summary } sleep(5) end end def comparer(source_1 = live_nodes_list, source_2 = file_nodes_list) @comparer ||= nodes_diff_class.new( source_1, source_2, original_tree: input_tagtree, logger: logger ).tap do log(:info) { "Comparing #{source_1.count} nodes with #{source_2.count} file nodes." } end end private def nodes_diff_class Eco::Data::Locations::NodeDiff::NodesDiff end def print_diff_details? true end def generate_live_nodes_file? false end def live_nodes_list @live_nodes_list ||= as_nodes_json(input_tagtree).tap do |list| log(:info) { "Converted live tree to list of #{list.count} hash-nodes" } end end # We accept csv input as a `:tree` or as `:nodes` # @note # 1. uses custom converter inherited from base case '01_tatree_to_list_case' # - `as_nodes_json` # 2. `org_tree` is native from `Eco::Data::Locations::NodeBase::CsvConvert` def file_nodes_list @file_nodes_list ||= as_nodes_json(org_tree(input_csv)).tap do |list| log(:info) { "Converted input csv file to list of #{list.count} hash-nodes" } end end end end end