aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZog2018-04-30 09:15:54 +0200
committerZog2018-05-07 15:03:07 +0200
commit7b336d1e47164a15c273f0899e8710e4fee273f8 (patch)
tree2fe44c50cf876fa150f9a97c6d4f64389a79c6bb
parent657fea85b193fb9908dcaa42391bec230e93d857 (diff)
downloadchouette-core-7b336d1e47164a15c273f0899e8710e4fee273f8.tar.bz2
Trigger compliance checks after imports
-rw-r--r--app/controllers/imports_controller.rb9
-rw-r--r--app/helpers/imports_helper.rb1
-rw-r--r--app/models/compliance_check_set.rb5
-rw-r--r--app/models/concerns/iev_interfaces/task.rb11
-rw-r--r--app/models/import/base.rb9
-rw-r--r--app/models/import/netex.rb10
-rw-r--r--app/models/import/resource.rb42
-rw-r--r--app/models/workbench.rb4
-rw-r--r--app/models/workgroup.rb5
-rw-r--r--app/views/imports/import/_netex.html.slim1
-rw-r--r--app/views/imports/import/_workbench.html.slim10
11 files changed, 97 insertions, 10 deletions
diff --git a/app/controllers/imports_controller.rb b/app/controllers/imports_controller.rb
index 8d7a723a0..b98d7da8d 100644
--- a/app/controllers/imports_controller.rb
+++ b/app/controllers/imports_controller.rb
@@ -4,6 +4,7 @@ class ImportsController < ChouetteController
include IevInterfaces
skip_before_action :authenticate_user!, only: [:download]
defaults resource_class: Import::Base, collection_name: 'imports', instance_name: 'import'
+ before_action :notify_parents
def download
if params[:token] == resource.token_download
@@ -18,7 +19,7 @@ class ImportsController < ChouetteController
def index_model
Import::Workbench
end
-
+
def build_resource
@import ||= Import::Workbench.new(*resource_params) do |import|
import.workbench = parent
@@ -43,4 +44,10 @@ class ImportsController < ChouetteController
}
)
end
+
+ def notify_parents
+ if Rails.env.development?
+ ParentNotifier.new(Import::Base).notify_when_finished
+ end
+ end
end
diff --git a/app/helpers/imports_helper.rb b/app/helpers/imports_helper.rb
index a297c2521..341f87037 100644
--- a/app/helpers/imports_helper.rb
+++ b/app/helpers/imports_helper.rb
@@ -3,6 +3,7 @@ module ImportsHelper
# Import statuses helper
def import_status(status, verbose: false)
+ return "" unless status
status = status.to_s.downcase
out = if %w[new running pending].include? status
content_tag :span, '', class: "fa fa-clock-o"
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
diff --git a/app/views/imports/import/_netex.html.slim b/app/views/imports/import/_netex.html.slim
index 5542e389f..2f341016a 100644
--- a/app/views/imports/import/_netex.html.slim
+++ b/app/views/imports/import/_netex.html.slim
@@ -2,6 +2,7 @@
.col-lg-6.col-md-6.col-sm-12.col-xs-12
- metadata = { t('.parent') => link_to(@import.parent.name, [@import.parent.workbench, @import.parent]) }
- metadata = metadata.update({t('.status') => import_status(@import.status, verbose: true) })
+ - metadata = metadata.update({t('.referential') => @import.referential ? link_to(@import.referential.name, [@import.referential]) : "-" })
= definition_list t('metadatas'), metadata
.col-lg-12
diff --git a/app/views/imports/import/_workbench.html.slim b/app/views/imports/import/_workbench.html.slim
index d384cbbe2..cec5d837c 100644
--- a/app/views/imports/import/_workbench.html.slim
+++ b/app/views/imports/import/_workbench.html.slim
@@ -30,13 +30,19 @@
), \
TableBuilderHelper::Column.new( \
name: t('.stif_control'), \
- attribute: '', \
+ attribute: Proc.new { |n| import_status(n.workbench_import_control_set&.status) }, \
sortable: false, \
+ link_to: lambda do |item| \
+ item.workbench_import_control_set.present? && [@import.workbench, item.workbench_import_control_set] \
+ end \
), \
TableBuilderHelper::Column.new( \
name: t('.organisation_control'), \
- attribute: '', \
+ attribute: Proc.new { |n| import_status(n.workgroup_import_control_set&.status) }, \
sortable: false, \
+ link_to: lambda do |item| \
+ item.workgroup_import_control_set.present? && [@import.workbench, item.workgroup_import_control_set] \
+ end \
) \
],
cls: 'table',