diff options
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/compliance_check_set.rb | 5 | ||||
| -rw-r--r-- | app/models/concerns/iev_interfaces/task.rb | 11 | ||||
| -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 | ||||
| -rw-r--r-- | app/models/workbench.rb | 4 | ||||
| -rw-r--r-- | app/models/workgroup.rb | 5 | 
7 files changed, 79 insertions, 7 deletions
| diff --git a/app/models/compliance_check_set.rb b/app/models/compliance_check_set.rb index 8b1dbdd68..eb0e23d82 100644 --- a/app/models/compliance_check_set.rb +++ b/app/models/compliance_check_set.rb @@ -68,6 +68,11 @@ class ComplianceCheckSet < ApplicationModel      end      update attributes +    import_resource&.next_step +  end + +  def import_resource +    referential&.import_resources.main_resources.last    end diff --git a/app/models/concerns/iev_interfaces/task.rb b/app/models/concerns/iev_interfaces/task.rb index 6be33734b..3e4dd52ca 100644 --- a/app/models/concerns/iev_interfaces/task.rb +++ b/app/models/concerns/iev_interfaces/task.rb @@ -56,13 +56,14 @@ module IevInterfaces::Task    end    def notify_parent -    return unless self.class.finished_statuses.include?(status) +    return false unless self.class.finished_statuses.include?(status) -    return unless parent.present? -    return if notified_parent_at +    return false unless parent.present? +    return false if notified_parent_at      parent.child_change      update_column :notified_parent_at, Time.now +    true    end    def children_succeedeed @@ -94,6 +95,10 @@ module IevInterfaces::Task      update attributes    end +  def successful? +    status.to_s == "successful" +  end +    def child_change      return if self.class.finished_statuses.include?(status)      update_status 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 diff --git a/app/models/workbench.rb b/app/models/workbench.rb index 1c54e8904..14406c9f4 100644 --- a/app/models/workbench.rb +++ b/app/models/workbench.rb @@ -51,6 +51,10 @@ class Workbench < ApplicationModel      where(name: DEFAULT_WORKBENCH_NAME).last    end +  def import_compliance_control_set +    ComplianceControlSet.find(import_compliance_control_set_id) +  end +    private    def initialize_output diff --git a/app/models/workgroup.rb b/app/models/workgroup.rb index 3e8409634..9ae5e564d 100644 --- a/app/models/workgroup.rb +++ b/app/models/workgroup.rb @@ -23,4 +23,9 @@ class Workgroup < ApplicationModel    def has_export? export_name      export_types.include? export_name    end + +  def import_compliance_control_set_id +    # XXX +    1 +  end  end | 
