diff options
Diffstat (limited to 'app/models/import/resource.rb')
| -rw-r--r-- | app/models/import/resource.rb | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/app/models/import/resource.rb b/app/models/import/resource.rb index 1951daacd..43690755d 100644 --- a/app/models/import/resource.rb +++ b/app/models/import/resource.rb @@ -4,5 +4,49 @@ class Import::Resource < ApplicationModel include IevInterfaces::Resource belongs_to :import, class_name: Import::Base + belongs_to :referential has_many :messages, class_name: "Import::Message", foreign_key: :resource_id + + scope :main_resources, ->{ where(resource_type: "referential") } + + def root_import + import = self.import + import = import.parent while import.parent + import + end + + def next_step + if root_import.class == Import::Workbench + + return unless netex_import&.successful? + + workbench.workgroup.import_compliance_control_sets.map do |key, label| + next unless (control_set = workbench.compliance_control_set(key)).present? + compliance_check_set = workbench_import_check_set key + if compliance_check_set.nil? + ComplianceControlSetCopyWorker.perform_async control_set.id, referential_id, root_import.class.name, root_import.id + end + end + end + end + + def workbench + import.workbench + end + + def workgroup + workbench.workgroup + end + + def netex_import + return unless self.resource_type == "referential" + import.children.where(name: self.reference).last + end + + def workbench_import_check_set key + return unless referential.present? + control_set = referential.workbench.compliance_control_set(key) + return unless control_set.present? + referential.compliance_check_sets.where(compliance_control_set_id: control_set.id, referential_id: referential_id).last + end end |
