From 695d6604f12515507e2e8d435370d30df5fc820d Mon Sep 17 00:00:00 2001
From: Robert
Date: Mon, 27 Nov 2017 10:07:30 +0100
Subject: Refs: #5006@3h;
Working out how to check for allowed lines vs. foreign lines
- Implement allowed_lines as `Organisation#lines_set`
- Pushed line_id related stuff into `lib/stif/codif_line_id.rb`
- Related Specs
---
lib/stif/codif_line_id.rb | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
create mode 100644 lib/stif/codif_line_id.rb
(limited to 'lib')
diff --git a/lib/stif/codif_line_id.rb b/lib/stif/codif_line_id.rb
new file mode 100644
index 000000000..b7f3c8bd5
--- /dev/null
+++ b/lib/stif/codif_line_id.rb
@@ -0,0 +1,16 @@
+module STIF
+ module CodifLineId extend self
+
+ LINE_OBJECT_ID_SEPERATOR = ':'
+
+ def extract_codif_line_id line_name
+ line_name.split(LINE_OBJECT_ID_SEPERATOR).last
+ end
+
+ def lines_set_from_functional_scope(functional_scope)
+ Set.new(
+ functional_scope
+ .map{ |line| extract_codif_line_id line })
+ end
+ end
+end
--
cgit v1.2.3
From 424496bc6e7b6f94b0f34d3c11fb95fd7f6088c5 Mon Sep 17 00:00:00 2001
From: Robert
Date: Mon, 27 Nov 2017 11:24:31 +0100
Subject: Refs: #5006@12h;
Implementing allowed vs foreign line lookup for the zip service
- Adapting `lib/stif/netex_file.rb` to expose the already implemented matching
- `app/services/zip_service.rb` augmented to check for allowed lines and returning forbidden lines
- Specs with fixtures and using the beforementioned new zip support in the specs
- Fixture directories for the new specs
---
lib/stif/netex_file.rb | 65 +++++++++++++++++++++++++++-----------------------
1 file changed, 35 insertions(+), 30 deletions(-)
(limited to 'lib')
diff --git a/lib/stif/netex_file.rb b/lib/stif/netex_file.rb
index a977c1ad3..b3e093727 100644
--- a/lib/stif/netex_file.rb
+++ b/lib/stif/netex_file.rb
@@ -2,8 +2,9 @@ module STIF
class NetexFile
CALENDAR_FILE_NAME = 'calendriers.xml'
- LINE_FILE_FORMAT = /^offre_.*\.xml$/
- XML_NAME_SPACE = "http://www.netex.org.uk/netex"
+ LINE_FILE_FORMAT = %r{\A offre_ (.*?) _ .* \. xml \z}x
+ XML_NAME_SPACE = "http://www.netex.org.uk/netex"
+
def initialize(file_name)
@file_name = file_name
@@ -22,49 +23,53 @@ module STIF
frames[entry_dir_name].parse_calendars(stream.read)
end
when LINE_FILE_FORMAT
- frames[entry_dir_name].add_offer_file(entry_file_name)
+ frames[entry_dir_name].add_offer_file($1)
end
end
end
frames.values
end
- end
+ class Frame
- class NetexFile::Frame
+ class << self
+ def get_line_object_id file_name
+ base_name = File.split(file_name).last
+ STIF::NetexFile::LINE_FILE_FORMAT.match(base_name).try(:[], 1)
+ end
+ end
- attr_accessor :name
+ attr_accessor :name
- def initialize(name)
- @name = name
- end
+ def initialize(name)
+ @name = name
+ end
+
+ def parse_calendars(calendars)
+ #
+ # 2017-03-01
+ # 2017-03-31
+ #
+ xml = Nokogiri::XML(calendars)
+ xml.xpath("//netex:ValidBetween", "netex" => NetexFile::XML_NAME_SPACE).each do |valid_between|
+ from_date = valid_between.xpath("netex:FromDate").try :text
+ to_date = valid_between.xpath("netex:ToDate").try :text
+ periods << Range.new(Date.parse(from_date), Date.parse(to_date))
+ end
+ end
- def parse_calendars(calendars)
- #
- # 2017-03-01
- # 2017-03-31
- #
- xml = Nokogiri::XML(calendars)
- xml.xpath("//netex:ValidBetween", "netex" => NetexFile::XML_NAME_SPACE).each do |valid_between|
- from_date = valid_between.xpath("netex:FromDate").try :text
- to_date = valid_between.xpath("netex:ToDate").try :text
- periods << Range.new(Date.parse(from_date), Date.parse(to_date))
+ def add_offer_file(line_object_id)
+ line_refs << line_object_id
end
- end
- def add_offer_file(file_name)
- if file_name =~ /^offre_([^_]*)_/
- line_refs << $1
+ def periods
+ @periods ||= []
end
- end
- def periods
- @periods ||= []
- end
+ def line_refs
+ @line_refs ||= []
+ end
- def line_refs
- @line_refs ||= []
end
-
end
end
--
cgit v1.2.3
From d157011c12b20cedbe4501c4d228ebcdac3647bc Mon Sep 17 00:00:00 2001
From: Robert
Date: Mon, 27 Nov 2017 11:27:16 +0100
Subject: Fixes: #5006@10h;
Implementation of Filtering Out Referentials with foreign lines in `app/workers/workbench_import_worker.rb`
- Using ZipService with the set of allowed lines of the organisation
- Fixing Integration Specs of the worker
- Refactoring, Debugging and Rebasing
---
lib/stif/my_workbench_scopes.rb | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'lib')
diff --git a/lib/stif/my_workbench_scopes.rb b/lib/stif/my_workbench_scopes.rb
index 89c4e659c..04bc93089 100644
--- a/lib/stif/my_workbench_scopes.rb
+++ b/lib/stif/my_workbench_scopes.rb
@@ -2,12 +2,13 @@ module Stif
class MyWorkbenchScopes
attr_accessor :workbench
+
def initialize(workbench)
@workbench = workbench
end
def line_scope(initial_scope)
- ids = self.parse_functional_scope
+ ids = parse_functional_scope
ids ? initial_scope.where(objectid: ids) : initial_scope
end
--
cgit v1.2.3
From 16d66dd5df93a11604ba29ea563fb7005b61367b Mon Sep 17 00:00:00 2001
From: Robert
Date: Thu, 7 Dec 2017 11:01:43 +0100
Subject: Refs #5006; CR pass I
---
lib/stif/codif_line_id.rb | 16 ----------------
lib/stif/codifligne_line_id.rb | 16 ++++++++++++++++
2 files changed, 16 insertions(+), 16 deletions(-)
delete mode 100644 lib/stif/codif_line_id.rb
create mode 100644 lib/stif/codifligne_line_id.rb
(limited to 'lib')
diff --git a/lib/stif/codif_line_id.rb b/lib/stif/codif_line_id.rb
deleted file mode 100644
index b7f3c8bd5..000000000
--- a/lib/stif/codif_line_id.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-module STIF
- module CodifLineId extend self
-
- LINE_OBJECT_ID_SEPERATOR = ':'
-
- def extract_codif_line_id line_name
- line_name.split(LINE_OBJECT_ID_SEPERATOR).last
- end
-
- def lines_set_from_functional_scope(functional_scope)
- Set.new(
- functional_scope
- .map{ |line| extract_codif_line_id line })
- end
- end
-end
diff --git a/lib/stif/codifligne_line_id.rb b/lib/stif/codifligne_line_id.rb
new file mode 100644
index 000000000..4021996a7
--- /dev/null
+++ b/lib/stif/codifligne_line_id.rb
@@ -0,0 +1,16 @@
+module STIF
+ module CodifligneLineId extend self
+
+ LINE_OBJECT_ID_SEPERATOR = ':'
+
+ def extract_codif_line_id line_name
+ line_name.split(LINE_OBJECT_ID_SEPERATOR).last
+ end
+
+ def lines_set_from_functional_scope(functional_scope)
+ Set.new(
+ functional_scope
+ .map{ |line| extract_codif_line_id line })
+ end
+ end
+end
--
cgit v1.2.3
From 9bde9a3d24e3893a7a4ee89c95044899e59c89f4 Mon Sep 17 00:00:00 2001
From: Robert
Date: Thu, 7 Dec 2017 11:15:01 +0100
Subject: Refs #5006@0.5h; CR pass II
---
lib/stif/codifligne_line_id.rb | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
(limited to 'lib')
diff --git a/lib/stif/codifligne_line_id.rb b/lib/stif/codifligne_line_id.rb
index 4021996a7..8c1bcc54b 100644
--- a/lib/stif/codifligne_line_id.rb
+++ b/lib/stif/codifligne_line_id.rb
@@ -3,14 +3,17 @@ module STIF
LINE_OBJECT_ID_SEPERATOR = ':'
- def extract_codif_line_id line_name
- line_name.split(LINE_OBJECT_ID_SEPERATOR).last
- end
-
def lines_set_from_functional_scope(functional_scope)
Set.new(
functional_scope
.map{ |line| extract_codif_line_id line })
end
+
+
+ private
+
+ def extract_codif_line_id line_name
+ line_name.split(LINE_OBJECT_ID_SEPERATOR).last
+ end
end
end
--
cgit v1.2.3
From 1e508ac3046bdc9f5c2c7b96959ab55912f9a680 Mon Sep 17 00:00:00 2001
From: Robert
Date: Thu, 7 Dec 2017 13:08:55 +0100
Subject: Refs #5006@0.5h; CR pass III / (i)
- refact of NetexFile#frames
---
lib/stif/netex_file.rb | 31 +++++++++++++++++++------------
1 file changed, 19 insertions(+), 12 deletions(-)
(limited to 'lib')
diff --git a/lib/stif/netex_file.rb b/lib/stif/netex_file.rb
index b3e093727..e58f22f08 100644
--- a/lib/stif/netex_file.rb
+++ b/lib/stif/netex_file.rb
@@ -2,7 +2,7 @@ module STIF
class NetexFile
CALENDAR_FILE_NAME = 'calendriers.xml'
- LINE_FILE_FORMAT = %r{\A offre_ (.*?) _ .* \. xml \z}x
+ LINE_FILE_FORMAT = %r{\A offre_ (? .*?) _ .* \. xml \z}x
XML_NAME_SPACE = "http://www.netex.org.uk/netex"
@@ -14,22 +14,29 @@ module STIF
frames = Hash.new { |h,k| h[k] = NetexFile::Frame.new(k) }
Zip::File.open(@file_name) do |zipfile|
zipfile.each do |entry|
- next unless entry.ftype == :file
-
- entry_dir_name, entry_file_name = File.split(entry.name)
- case entry_file_name
- when CALENDAR_FILE_NAME
- entry.get_input_stream do |stream|
- frames[entry_dir_name].parse_calendars(stream.read)
- end
- when LINE_FILE_FORMAT
- frames[entry_dir_name].add_offer_file($1)
- end
+ add_frame(to_frames: frames, from_entry: entry) if entry.ftype == :file
+
end
end
frames.values
end
+
+ private
+
+ def add_frame(to_frames:, from_entry:)
+ entry_dir_name, entry_file_name = File.split(from_entry.name)
+ case entry_file_name
+ when CALENDAR_FILE_NAME
+ from_entry.get_input_stream do |stream|
+ to_frames[entry_dir_name].parse_calendars(stream.read)
+ end
+ when LINE_FILE_FORMAT
+ to_frames[entry_dir_name].add_offer_file($1)
+ end
+ end
+
+
class Frame
class << self
--
cgit v1.2.3
From b183419ac757b49f85f095b255a50ecc434a1217 Mon Sep 17 00:00:00 2001
From: Robert
Date: Thu, 7 Dec 2017 13:17:24 +0100
Subject: Refs #5006@0.5h; CR pass III / (ii)
- refact of NetexFile#frames finished, got rid of mystery global $1
---
lib/stif/netex_file.rb | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
(limited to 'lib')
diff --git a/lib/stif/netex_file.rb b/lib/stif/netex_file.rb
index e58f22f08..cbf164c8f 100644
--- a/lib/stif/netex_file.rb
+++ b/lib/stif/netex_file.rb
@@ -15,7 +15,6 @@ module STIF
Zip::File.open(@file_name) do |zipfile|
zipfile.each do |entry|
add_frame(to_frames: frames, from_entry: entry) if entry.ftype == :file
-
end
end
frames.values
@@ -26,13 +25,17 @@ module STIF
def add_frame(to_frames:, from_entry:)
entry_dir_name, entry_file_name = File.split(from_entry.name)
- case entry_file_name
- when CALENDAR_FILE_NAME
+
+ if CALENDAR_FILE_NAME === entry_file_name
from_entry.get_input_stream do |stream|
to_frames[entry_dir_name].parse_calendars(stream.read)
end
- when LINE_FILE_FORMAT
- to_frames[entry_dir_name].add_offer_file($1)
+ return
+ end
+
+ line_file_match = LINE_FILE_FORMAT.match( entry_file_name )
+ if line_file_match
+ to_frames[entry_dir_name].add_offer_file( line_file_match['line_object_id'])
end
end
--
cgit v1.2.3
From d4f71c7aaf775b422c97a19c06bc94d2e0a98d76 Mon Sep 17 00:00:00 2001
From: Robert
Date: Thu, 7 Dec 2017 13:34:38 +0100
Subject: Refs #5006@0.5h; CR pass IV
- simple simplification (as opposed to complicated simplifications ^^)
---
lib/stif/netex_file.rb | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'lib')
diff --git a/lib/stif/netex_file.rb b/lib/stif/netex_file.rb
index cbf164c8f..db64ed05e 100644
--- a/lib/stif/netex_file.rb
+++ b/lib/stif/netex_file.rb
@@ -44,8 +44,8 @@ module STIF
class << self
def get_line_object_id file_name
- base_name = File.split(file_name).last
- STIF::NetexFile::LINE_FILE_FORMAT.match(base_name).try(:[], 1)
+ base_name = File.basename(file_name)
+ STIF::NetexFile::LINE_FILE_FORMAT.match(base_name).try(:[], 'line_object_id')
end
end
--
cgit v1.2.3