Class: Interchange::ImportsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Interchange::ImportsController
- Defined in:
- app/controllers/interchange/imports_controller.rb
Overview
Controller for a import related functionality, as a RESTful resource.
Instance Method Summary collapse
-
#create ⇒ Object
This responds to the request to do the import.
-
#initialize ⇒ ImportsController
constructor
This constructor sets up Reader class that we offload the low level import work to.
-
#show ⇒ Object
Shows the page of import options, as well as the results of the last import operation, if the server hasn’t been bounced since that was last performed.
Constructor Details
#initialize ⇒ ImportsController
This constructor sets up Reader class that we offload the low level import work to.
7 8 9 10 |
# File 'app/controllers/interchange/imports_controller.rb', line 7 def initialize super @reader = Interchange::Reader.new end |
Instance Method Details
#create ⇒ Object
This responds to the request to do the import. We invoke a helper method to handle the import of a given model class, one at a time. Possible param values that can be provided:
* import_patients - Whether to import patients. Pass 1 for true.
* import_physicians - Whether to import physicians. Pass 1 for true.
* destroy_existing - Whether to destroy existing data before starting the import. Pass 1 for true.
* cleanup - Whether to delete source files that are successfully imported. Pass 1 for true.
We determine what models to import from the params provided, as well as whether to delete existing data prior to import and source import data after successful import. Once complete, we redirect to the show action, with a flash message built from the Interchange::Reader class’ tally of results.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/controllers/interchange/imports_controller.rb', line 37 def create log 'In create method. Initiating an import operation now.' log "params: #{params}" # Determine what models are to be included: model_classes = [] model_classes << Patient if params[:import_patients] model_classes << Physician if params[:import_physicians] model_classes << DocumentTemplate if params[:import_document_templates] model_classes << DataSet if params[:import_data_sets] # Determine what options have been requested: destroy_existing = params[:destroy_existing] cleanup = params[:cleanup] duplicate_strategy = case params[:duplicates] when 'Allow' then Enums::DuplicateStrategy::ALLOW when 'Replace' then Enums::DuplicateStrategy::REPLACE when 'Skip' then Enums::DuplicateStrategy::SKIP else Enums::DuplicateStrategy::SKIP end @reader.mark_import_operation do # Kick off the underlying import operation on the model(s) requested: model_classes.each do |model_class| import model_class, destroy_existing, cleanup, duplicate_strategy end end redirect_to interchange_import_path, @reader.operation_results[:flash_hash] end |
#show ⇒ Object
Shows the page of import options, as well as the results of the last import operation, if the server hasn’t been bounced since that was last performed.
15 16 17 18 19 20 21 22 23 |
# File 'app/controllers/interchange/imports_controller.rb', line 15 def show log 'ImportController: show' = {class: 'active'} 'Import', '#', # breadcrumbs_on_rails call # Retrieve results of the last import, so we can display that in our view: @last_import_summary = Interchange::Reader.instance_variable_get(:@last_import_summary) end |