diff options
| author | Zog | 2018-04-30 09:15:54 +0200 | 
|---|---|---|
| committer | Zog | 2018-05-07 15:03:07 +0200 | 
| commit | 7b336d1e47164a15c273f0899e8710e4fee273f8 (patch) | |
| tree | 2fe44c50cf876fa150f9a97c6d4f64389a79c6bb /app/models/import | |
| parent | 657fea85b193fb9908dcaa42391bec230e93d857 (diff) | |
| download | chouette-core-7b336d1e47164a15c273f0899e8710e4fee273f8.tar.bz2 | |
Trigger compliance checks after imports
Diffstat (limited to 'app/models/import')
| -rw-r--r-- | app/models/import/base.rb | 9 | ||||
| -rw-r--r-- | app/models/import/netex.rb | 10 | ||||
| -rw-r--r-- | app/models/import/resource.rb | 42 | 
3 files changed, 57 insertions, 4 deletions
| diff --git a/app/models/import/base.rb b/app/models/import/base.rb index 606c39974..baa25c3df 100644 --- a/app/models/import/base.rb +++ b/app/models/import/base.rb @@ -32,8 +32,13 @@ class Import::Base < ApplicationModel      Rails.logger.info "update_referentials for #{inspect}"      return unless self.class.finished_statuses.include?(status) -    children.each do |import| -      import.referential.update(ready: true) if import.referential +    # We treat all created referentials in a batch +    # If a single fails, we consider they all failed +    # Ohana means family ! +    if self.successful? +      children.map(&:referential).compact.each &:active! +    else +      children.map(&:referential).compact.each &:failed!      end    end diff --git a/app/models/import/netex.rb b/app/models/import/netex.rb index f64a18e98..b4422328c 100644 --- a/app/models/import/netex.rb +++ b/app/models/import/netex.rb @@ -18,8 +18,14 @@ class Import::Netex < Import::Base    end    def notify_parent -    super -    main_resource.update_status_from_importer self.status +    if super +      main_resource.update_status_from_importer self.status +      next_step +    end +  end + +  def next_step +    main_resource.next_step    end    def create_message args diff --git a/app/models/import/resource.rb b/app/models/import/resource.rb index e6de935ae..27dc367a8 100644 --- a/app/models/import/resource.rb +++ b/app/models/import/resource.rb @@ -7,14 +7,56 @@ class Import::Resource < ApplicationModel    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 + +      # XXX +      # return unless netex_import&.successful? + +      if workbench.import_compliance_control_set_id.present? && workbench_import_control_set.nil? +        ComplianceControlSetCopyWorker.perform_async workbench.import_compliance_control_set_id, referential_id +        return +      end + +      # XXX +      # return if workbench_import_control_set && !workbench_import_control_set.successful? + +      if workgroup.import_compliance_control_set_id.present? && workgroup_import_control_set.nil? +        ComplianceControlSetCopyWorker.perform_async workgroup.import_compliance_control_set_id, referential_id +      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_control_set +    return unless referential.present? +    return unless referential.workbench.import_compliance_control_set_id.present? +    referential.compliance_check_sets.where(compliance_control_set_id: referential.workbench.import_compliance_control_set_id, referential_id: referential_id).last +  end + +  def workgroup_import_control_set +    return unless referential.present? +    return unless referential.workbench.workgroup.import_compliance_control_set_id.present? +    referential.compliance_check_sets.where(compliance_control_set_id: referential.workbench.workgroup.import_compliance_control_set_id, referential_id: referential_id).last +  end  end | 
