diff options
Diffstat (limited to 'app/models/import.rb')
| -rw-r--r-- | app/models/import.rb | 90 |
1 files changed, 5 insertions, 85 deletions
diff --git a/app/models/import.rb b/app/models/import.rb index 078f1698e..8ffac5c5e 100644 --- a/app/models/import.rb +++ b/app/models/import.rb @@ -1,87 +1,7 @@ -require 'open-uri' +class Import < ActiveRecord::Base + mount_uploader :file, ImportUploader + belongs_to :workbench + belongs_to :referential -class Import - include JobConcern - - def initialize( response ) - @datas = response - end - - def report? - links["action_report"].present? - end - - def report - Rails.cache.fetch("#{cache_key}/action_report", expires_in: cache_expiration) do - report_path = links["action_report"] - if report_path - response = Ievkit.get(report_path) - ImportReport.new(response) - else - nil - end - end - end - - def rule_parameter_set? - links["validation_params"].present? - end - - def rule_parameter_set - Rails.cache.fetch("#{cache_key}/validation_params", expires_in: cache_expiration) do - rule_parameter_set_path = links["validation_params"] - if rule_parameter_set_path - response = Ievkit.get(rule_parameter_set_path) - rule_parameter_set = RuleParameterSet.new(:name => "", :import => self).tap { |rps| rps.parameters = response.validation } - else - nil - end - end - end - - def compliance_check? - links["validation_report"].present? - end - - def compliance_check_validation_report - puts "compliance_check_validation_report" - Rails.cache.fetch("#{cache_key}/validation_report", expires_in: cache_expiration) do - compliance_check_path = links["validation_report"] - if compliance_check_path - response = Ievkit.get(compliance_check_path) - ComplianceCheckResult.new(response) - else - nil - end - end - end - - def destroy - delete_path = links["delete"] - cancel_path = links["cancel"] - - if delete_path - Ievkit.delete(delete_path) - elsif cancel_path - Ievkit.delete(cancel_path) - else - nil - end - end - - def file_path? - links["data"].present? - end - - def file_path - links["data"] - end - - def filename - File.basename(file_path) if file_path - end - - def filename_extension - File.extname(filename).gsub(".", "") if filename - end + validates :file, presence: true end |
