aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/services/zip_service.rb47
-rw-r--r--app/views/shared/iev_interfaces/_messages.html.slim7
-rw-r--r--app/workers/workbench_import_worker/object_state_updater.rb27
3 files changed, 68 insertions, 13 deletions
diff --git a/app/services/zip_service.rb b/app/services/zip_service.rb
index 7166e6448..188e1b3c8 100644
--- a/app/services/zip_service.rb
+++ b/app/services/zip_service.rb
@@ -1,8 +1,8 @@
class ZipService
- class Subdir < Struct.new(:name, :stream, :spurious, :foreign_lines)
+ class Subdir < Struct.new(:name, :stream, :spurious, :foreign_lines, :missing_calendar, :wrong_calendar)
def ok?
- foreign_lines.empty? && spurious.empty?
+ foreign_lines.empty? && spurious.empty? && !missing_calendar && !wrong_calendar
end
end
@@ -38,8 +38,23 @@ class ZipService
add_to_current_output entry
end
+ def validate entry
+ if is_calendar_file?(entry.name)
+ @current_calendar_is_missing = false
+ if wrong_calendar_data?(entry)
+ @current_calendar_is_wrong = true
+ return false
+ end
+ end
+ return false if is_spurious?(entry.name)
+ return false if is_foreign_line?(entry.name)
+ true
+ end
+
def add_to_current_output entry
- return if is_spurious!(entry.name) || is_foreign_line!(entry.name)
+ p "entry.name: #{entry.name}"
+ return unless validate(entry)
+ p "Adding"
current_output.put_next_entry entry.name
write_to_current_output entry.get_input_stream
@@ -48,7 +63,7 @@ class ZipService
def write_to_current_output input_stream
# the condition below is true for directory entries
return if Zip::NullInputStream == input_stream
- current_output.write input_stream.read
+ current_output.write input_stream.read
end
def finish_current_output
@@ -58,7 +73,9 @@ class ZipService
# Second part of the solution, yield the closed stream
current_output.close_buffer,
current_spurious.to_a,
- foreign_lines)
+ foreign_lines,
+ @current_calendar_is_missing,
+ @current_calendar_is_wrong)
end
end
@@ -68,6 +85,8 @@ class ZipService
@current_output = Zip::OutputStream.new(StringIO.new(''), true, nil)
@current_spurious = Set.new
@foreign_lines = []
+ @current_calendar_is_missing = true
+ @current_calendar_is_wrong = false
end
def entry_key entry
@@ -75,7 +94,7 @@ class ZipService
entry.name.split('/').first
end
- def is_spurious! entry_name
+ def is_spurious? entry_name
segments = entry_name.split('/', 3)
return false if segments.size < 3
@@ -83,11 +102,25 @@ class ZipService
return true
end
- def is_foreign_line! entry_name
+ def is_foreign_line? entry_name
STIF::NetexFile::Frame.get_short_id(entry_name).tap do | line_object_id |
return nil unless line_object_id
return nil if line_object_id.in? allowed_lines
foreign_lines << line_object_id
end
end
+
+ def is_calendar_file? entry_name
+ entry_name =~ /calendriers.xml$/
+ end
+
+ def wrong_calendar_data? entry
+ content = entry.get_input_stream.read
+ period = STIF::NetexFile::Frame.parse_calendars content.to_s
+ return true unless period
+ return true unless period.first
+ return true unless period.end
+ return true unless period.first <= period.end
+ false
+ end
end
diff --git a/app/views/shared/iev_interfaces/_messages.html.slim b/app/views/shared/iev_interfaces/_messages.html.slim
index 14157a88d..4e2c4d849 100644
--- a/app/views/shared/iev_interfaces/_messages.html.slim
+++ b/app/views/shared/iev_interfaces/_messages.html.slim
@@ -1,14 +1,15 @@
- if messages.any?
ul.list-unstyled.import_message-list
- messages.order(:created_at).each do | message |
+ - width = message.resource_attributes.present? ? 6 : 12
li
.row class=bootstrap_class_for_message_criticity(message.criticity)
- if message.message_attributes && message.message_attributes["line"]
.col-md-1= "L. #{message.message_attributes["line"]}"
- .col-md-5= export_message_content message
+ div class="col-md-#{width-1}"= export_message_content message
- else
- .col-md-6= export_message_content message
+ div class="col-md-#{width}"= export_message_content message
.col-md-6
- - if message.resource_attributes
+ - if message.resource_attributes.present?
pre
= JSON.pretty_generate message.resource_attributes || {}
diff --git a/app/workers/workbench_import_worker/object_state_updater.rb b/app/workers/workbench_import_worker/object_state_updater.rb
index 67bdc0654..1edc6b9a1 100644
--- a/app/workers/workbench_import_worker/object_state_updater.rb
+++ b/app/workers/workbench_import_worker/object_state_updater.rb
@@ -6,9 +6,10 @@ class WorkbenchImportWorker
workbench_import.update( total_steps: count )
update_spurious entry
update_foreign_lines entry
+ update_missing_calendar entry
+ update_wrong_calendar entry
end
-
private
def update_foreign_lines entry
@@ -19,7 +20,7 @@ class WorkbenchImportWorker
message_attributes: {
'source_filename' => workbench_import.file.file.file,
'foreign_lines' => entry.foreign_lines.join(', ')
- })
+ })
end
def update_spurious entry
@@ -30,7 +31,27 @@ class WorkbenchImportWorker
message_attributes: {
'source_filename' => workbench_import.file.file.file,
'spurious_dirs' => entry.spurious.join(', ')
- })
+ })
+ end
+
+ def update_missing_calendar entry
+ return unless entry.missing_calendar
+ workbench_import.messages.create(
+ criticity: :error,
+ message_key: 'missing_calendar_in_zip_file',
+ message_attributes: {
+ 'source_filename' => entry.name
+ })
+ end
+
+ def update_wrong_calendar entry
+ return unless entry.wrong_calendar
+ workbench_import.messages.create(
+ criticity: :error,
+ message_key: 'wrong_calendar_in_zip_file',
+ message_attributes: {
+ 'source_filename' => entry.name
+ })
end
end
end