Class: Eco::API::UseCases::OozeSamples::RegisterMigrationCase
- Inherits:
-
RegisterUpdateCase
- Object
- Common::Loaders::Base
- Common::Loaders::CaseBase
- Common::Loaders::UseCase
- OozeBaseCase
- RegisterUpdateCase
- Eco::API::UseCases::OozeSamples::RegisterMigrationCase
- Includes:
- HelpersMigration
- Defined in:
- lib/eco/api/usecases/ooze_samples/register_migration_case.rb
Overview
- You can define methods
filtersandsearchto 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:
- field label name (String or RegExp body/source),
- 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.
- This file format expects an object {} where keys are field types (i.e. "select", "plain_text")
and the value is an array with either:
- You may either
- define the
process_oozemethod calling super with a block: super.do || - of define the function
custom_processing(draft, source, fields_tracker: nil)
- define the
- 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_hookswith 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
-
#csv ⇒ Object
readonly
Returns the value of attribute csv.
Attributes included from Language::AuxiliarLogger
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
Instance Method Summary collapse
- #main(session, options, usecase, &block) ⇒ Object
-
#process_ooze ⇒ Object
This method is expected to finalize the copying/adjustment of the draft entry.
Methods included from HelpersMigration::Copying
#copy_field_content, #copy_generic_paired_fields, #copy_hooked_fields, #session, #to_regex, #with_src_dst_field_pair
Methods included from Language::AuxiliarLogger
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
Methods included from Helpers::Creatable
Methods included from Helpers::Rescuable
Methods inherited from Common::Loaders::UseCase
Methods included from Common::Loaders::UseCase::CliIdentify
Methods included from Common::Loaders::UseCase::TargetModel
Methods included from Common::Loaders::UseCase::Type
Methods inherited from Common::Loaders::CaseBase
#name, name_only_once!, original_name
Methods inherited from Common::Loaders::Base
<=>, created_at, #initialize, set_created_at!
Methods included from Language::Klass::InheritableClassVars
#inheritable_attrs, #inheritable_class_vars, #inherited
Methods included from Language::Klass::Naming
#instance_variable_name, #to_constant
Methods included from Language::Klass::Hierarchy
Methods included from Language::Klass::Builder
Methods included from Language::Klass::Uid
Methods included from Language::Klass::Resolver
#class_resolver, #resolve_class
Methods included from Language::Klass::Const
#if_const, #redef_without_warning
Constructor Details
This class inherits a constructor from Eco::API::Common::Loaders::UseCase
Instance Attribute Details
#csv ⇒ Object (readonly)
Returns the value of attribute csv.
44 45 46 |
# File 'lib/eco/api/usecases/ooze_samples/register_migration_case.rb', line 44 def csv @csv end |
Instance Method Details
#main(session, options, usecase, &block) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/eco/api/usecases/ooze_samples/register_migration_case.rb', line 46 def main(session, , usecase, &block) if [:dry_run] @csv = [] super else CSV.open(out_csv_filename, 'w') do |csv| @csv = csv csv << %w[src_page_id dst_page_id] super(session, , usecase, &block) end log(:info) { "File '#{out_csv_filename}' has been created." } end end |
#process_ooze ⇒ Object
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
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 95 96 97 98 99 100 101 102 |
# File 'lib/eco/api/usecases/ooze_samples/register_migration_case.rb', line 68 def process_ooze # rubocop:disable Metrics/AbcSize 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. << %w[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 msg = pairing_tracking.report_src_unpaired( only_present: !self.class::REPORT_SRC_EMTPY, only_indexed: !self.class::REPORT_SRC_DEINDEX ) log(:warn) { msg } if msg 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 } if msg msg = pairing_tracking.report_dst_unpaired( only_required: false, exclude_ximport: !self.class::REPORT_DST_XIMPORT ) log(:warn) { msg } if msg end end end |