Class: Eco::API::UseCases::OozeSamples::RegisterMigrationCase

Inherits:
RegisterUpdateCase show all
Includes:
HelpersMigration
Defined in:
lib/eco/api/usecases/ooze_samples/register_migration_case.rb

Overview

Note:
  • You can define methods filters and search to change the target entries of the register
  • You can define a json file named after your use case file (i.e. new_training.json) to pair source-destination fields:
    • This file format expects an object {} where keys are field types (i.e. "select", "plain_text") and the value is an array with either:
      1. field label name (String or RegExp body/source),
      2. or an object with key-value being source-destination label names (also supports RegExp body/source)
    • Example: ["severity of .*:", {"type of event:" => "type of incident:"]}
    • "all" as type will target all type of fields.
    • Caution with this! Copying between fields of different types is not yet supported.
  • You may either
    1. define the process_ooze method calling super with a block: super.do ||
    2. of define the function custom_processing(draft, source, fields_tracker: nil)
  • You can define a callback function, paired_fields_post_callback(src_fld, dst_fld, pairing_tracking = nil)
    • It will be called after copying by using any of the pairing methods, and allows to introduce modifications such as selection option mappings
  • You may define a method called excluded_field_hooks with same syntax as the json pairing file
    • This will exclude as source and destination targets any fields matching those patterns.
    • This is specially useful to discard rich text field guidelines (i.e. {"rich_text" => [".*guideline:"]})

Use case to offer the basics to migrate a register by creating new entries This case expects options[:source][:register_id]

Constant Summary collapse

EXCLUDE_XIMPORT =

whether or not it should try to pair src <-> dst ximport fields:

false
REPORT_DST_XIMPORT =

whether or not it should warn on unpaired destination ximport fields:

true
REPORT_SRC_EMTPY =

whether or not it should warn on unpaired source fields that are empty (no data loss):

false
REPORT_SRC_DEINDEX =

whether or not it should warn on unpaired source fields that are deindexed (low potential of data loss):

false

Constants included from Helpers::Filters

Helpers::Filters::FILTER_TIME_FORMAT

Constants inherited from OozeBaseCase

OozeBaseCase::DRY_COUNT, OozeBaseCase::SAVE_PATCH

Instance Attribute Summary collapse

Attributes inherited from RegisterUpdateCase

#attempted_ooze_updates, #created_oozes, #dupped_search_oozes, #failed_update_oozes, #non_retrieved_oozes, #ooze_create_attempts, #ooze_result_ids, #retrieved_oozes, #total_search_oozes, #updated_oozes

Attributes inherited from OozeBaseCase

#target

Attributes included from Language::AuxiliarLogger

#logger

Instance Method Summary collapse

Methods included from HelpersMigration::Copying

#copy_field_content, #copy_generic_paired_fields, #copy_hooked_fields, #logger, #session, #to_regex, #with_src_dst_field_pair

Methods included from Helpers::Filters

#date_range_filter, #days, #daystart, #field_key_name, #midnight, #previous_sunday, #set_time, #sunday, #tags_filter, #this_monday, #to_date_filter, #today, #weeks

Methods included from Helpers::Shortcuts

#bracked_regex, #clean_question, #is_number?, #non_letters_regex, #normalize_string, #object_reference, #same_string?, #simplify_string, #titleize, #to_i

Methods inherited from RegisterUpdateCase

batch_size

Methods included from Helpers::Creatable

validate_base_type!

Methods included from Helpers::Rescuable

validate_base_type!

Methods inherited from Common::Loaders::UseCase

cli, cli!, #cli_apply!, #initialize, type, #type

Methods inherited from Common::Loaders::CaseBase

#name, name_only_once!

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

Methods included from Language::AuxiliarLogger

#log

Constructor Details

This class inherits a constructor from Eco::API::Common::Loaders::UseCase

Instance Attribute Details

#csvObject (readonly)

Returns the value of attribute csv.



43
44
45
# File 'lib/eco/api/usecases/ooze_samples/register_migration_case.rb', line 43

def csv
  @csv
end

Instance Method Details

#main(session, options, usecase, &block) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/eco/api/usecases/ooze_samples/register_migration_case.rb', line 45

def main(session, options, usecase, &block)
  if options[:dry_run]
    @csv = []
    super(session, options, usecase, &block)
  else
    CSV.open(out_csv_filename, "w") do |csv|
      @csv = csv
      csv << ["src_page_id", "dst_page_id"]
      super(session, options, usecase, &block)
    end
    log(:info) { "File '#{out_csv_filename}' has been created." }
  end
end

#process_oozeObject

Note:

At this stage, the RegisterMigration case has already populated the draft where source and destination fields(in the draft) could be paired.

This method is expected to finalize the copying/adjustment of the draft entry. def custom_processing(draft, source, fields_tracker: nil) draft.tags << source.tags.to_a # More custom logics end



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/eco/api/usecases/ooze_samples/register_migration_case.rb', line 67

def process_ooze
  with_target_stage(self.class::SOURCE_STAGE) do |source|
    draft_reference = object_reference(source)
    creating_new_page(draft_reference, template_id: elf.class::TEMPLATE_ID) do |draft|
      draft.base_tags << ["IMPORTED", "MIGRATED"]

      pairing_tracking = copy_pairings(source, draft)

      if respond_to?(:custom_processing, true)
        custom_processing(draft, source, fields_tracker: pairing_tracking)
      elsif block_given?
        yield(draft, source, fields_tracker: pairing_tracking)
      end

      if msg = pairing_tracking.report_src_unpaired(only_present: !self.class::REPORT_SRC_EMTPY, only_indexed: !self.class::REPORT_SRC_DEINDEX)
        log(:warn) { msg }
      end

      if msg = pairing_tracking.report_multi_pairs(only_present: !self.class::REPORT_SRC_EMTPY, only_indexed: !self.class::REPORT_SRC_DEINDEX, dst_exclude_ximport: !self.class::REPORT_DST_XIMPORT)
        log(:warn) { msg }
      end

      if msg = pairing_tracking.report_dst_unpaired(only_required: false, exclude_ximport: !self.class::REPORT_DST_XIMPORT)
        log(:warn) { msg }
      end
    end
  end
end