aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXinhui2016-02-22 15:31:31 +0100
committerXinhui2016-02-22 15:31:31 +0100
commit0a1ffa22d97160797d2c96debbc99b31792a40c5 (patch)
tree7cea5119ddf42cbfe8d1e52c6d28096979830cd4
parentd49f47b4ac1db2cd88b96d830772bb7773924601 (diff)
downloadchouette-core-0a1ffa22d97160797d2c96debbc99b31792a40c5.tar.bz2
Merge NinoxeExtension concerns
-rw-r--r--app/models/chouette/access_point.rb2
-rw-r--r--app/models/chouette/company.rb1
-rw-r--r--app/models/chouette/connection_link.rb1
-rw-r--r--app/models/chouette/group_of_line.rb1
-rw-r--r--app/models/chouette/journey_pattern.rb1
-rw-r--r--app/models/chouette/line.rb1
-rw-r--r--app/models/chouette/network.rb1
-rw-r--r--app/models/chouette/route.rb2
-rw-r--r--app/models/chouette/stop_area.rb5
-rw-r--r--app/models/chouette/time_table.rb6
-rw-r--r--app/models/chouette/trident_active_record.rb11
-rw-r--r--app/models/chouette/vehicle_journey.rb7
-rw-r--r--app/models/concerns/company_restrictions.rb25
-rw-r--r--app/models/concerns/connection_link_restrictions.rb13
-rw-r--r--app/models/concerns/group_of_line_restrictions.rb25
-rw-r--r--app/models/concerns/journey_pattern_restrictions.rb20
-rw-r--r--app/models/concerns/line_restrictions.rb29
-rw-r--r--app/models/concerns/network_restrictions.rb25
-rw-r--r--app/models/concerns/objectid_restrictions.rb (renamed from lib/ninoxe_extension/hub/objectid_restrictions.rb)3
-rw-r--r--app/models/concerns/projection_fields.rb60
-rw-r--r--app/models/concerns/route_restrictions.rb25
-rw-r--r--app/models/concerns/stop_area_restrictions.rb63
-rw-r--r--app/models/concerns/time_table_restrictions.rb18
-rw-r--r--app/models/concerns/vehicle_journey_restrictions.rb15
-rw-r--r--app/models/referential.rb77
-rw-r--r--lib/ninoxe_extension/hub/company_restrictions.rb28
-rw-r--r--lib/ninoxe_extension/hub/connection_link_restrictions.rb16
-rw-r--r--lib/ninoxe_extension/hub/group_of_line_restrictions.rb29
-rw-r--r--lib/ninoxe_extension/hub/journey_pattern_restrictions.rb24
-rw-r--r--lib/ninoxe_extension/hub/line_restrictions.rb33
-rw-r--r--lib/ninoxe_extension/hub/network_restrictions.rb28
-rw-r--r--lib/ninoxe_extension/hub/route_restrictions.rb29
-rw-r--r--lib/ninoxe_extension/hub/stop_area_restrictions.rb67
-rw-r--r--lib/ninoxe_extension/hub/time_table_restrictions.rb22
-rw-r--r--lib/ninoxe_extension/hub/vehicle_journey_restrictions.rb19
-rw-r--r--lib/ninoxe_extension/projection_fields.rb63
-rw-r--r--spec/models/chouette/stop_area_spec.rb4
-rw-r--r--spec/models/chouette/trident_active_record_spec.rb30
38 files changed, 371 insertions, 458 deletions
diff --git a/app/models/chouette/access_point.rb b/app/models/chouette/access_point.rb
index 43c8e1b3a..317b19b26 100644
--- a/app/models/chouette/access_point.rb
+++ b/app/models/chouette/access_point.rb
@@ -5,6 +5,8 @@ class Chouette::AccessPoint < Chouette::TridentActiveRecord
# FIXME http://jira.codehaus.org/browse/JRUBY-6358
self.primary_key = "id"
include Geokit::Mappable
+ include ProjectionFields
+
has_many :access_links, :dependent => :destroy
belongs_to :stop_area
diff --git a/app/models/chouette/company.rb b/app/models/chouette/company.rb
index d0375b2e6..8ddd4c37d 100644
--- a/app/models/chouette/company.rb
+++ b/app/models/chouette/company.rb
@@ -1,4 +1,5 @@
class Chouette::Company < Chouette::TridentActiveRecord
+ include CompanyRestrictions
has_many :lines
validates_format_of :registration_number, :with => %r{\A[0-9A-Za-z_-]+\Z}, :allow_nil => true, :allow_blank => true
diff --git a/app/models/chouette/connection_link.rb b/app/models/chouette/connection_link.rb
index 045f7c1d9..e225c2fae 100644
--- a/app/models/chouette/connection_link.rb
+++ b/app/models/chouette/connection_link.rb
@@ -1,4 +1,5 @@
class Chouette::ConnectionLink < Chouette::TridentActiveRecord
+ include ConnectionLinkRestrictions
# FIXME http://jira.codehaus.org/browse/JRUBY-6358
self.primary_key = "id"
diff --git a/app/models/chouette/group_of_line.rb b/app/models/chouette/group_of_line.rb
index 1c1ae5f4c..f00db3164 100644
--- a/app/models/chouette/group_of_line.rb
+++ b/app/models/chouette/group_of_line.rb
@@ -1,4 +1,5 @@
class Chouette::GroupOfLine < Chouette::TridentActiveRecord
+ include GroupOfLineRestrictions
# FIXME http://jira.codehaus.org/browse/JRUBY-6358
self.primary_key = "id"
diff --git a/app/models/chouette/journey_pattern.rb b/app/models/chouette/journey_pattern.rb
index d48733edb..9b2b2a9da 100644
--- a/app/models/chouette/journey_pattern.rb
+++ b/app/models/chouette/journey_pattern.rb
@@ -1,4 +1,5 @@
class Chouette::JourneyPattern < Chouette::TridentActiveRecord
+ include JourneyPatternRestrictions
# FIXME http://jira.codehaus.org/browse/JRUBY-6358
self.primary_key = "id"
diff --git a/app/models/chouette/line.rb b/app/models/chouette/line.rb
index d69203233..b1e9940d3 100644
--- a/app/models/chouette/line.rb
+++ b/app/models/chouette/line.rb
@@ -1,4 +1,5 @@
class Chouette::Line < Chouette::TridentActiveRecord
+ include LineRestrictions
# FIXME http://jira.codehaus.org/browse/JRUBY-6358
self.primary_key = "id"
diff --git a/app/models/chouette/network.rb b/app/models/chouette/network.rb
index a631d70ec..c8926506c 100644
--- a/app/models/chouette/network.rb
+++ b/app/models/chouette/network.rb
@@ -1,4 +1,5 @@
class Chouette::Network < Chouette::TridentActiveRecord
+ include NetworkRestrictions
# FIXME http://jira.codehaus.org/browse/JRUBY-6358
self.primary_key = "id"
diff --git a/app/models/chouette/route.rb b/app/models/chouette/route.rb
index d5e39ac12..8949a6bc2 100644
--- a/app/models/chouette/route.rb
+++ b/app/models/chouette/route.rb
@@ -1,4 +1,6 @@
class Chouette::Route < Chouette::TridentActiveRecord
+ include RouteRestrictions
+
# FIXME http://jira.codehaus.org/browse/JRUBY-6358
self.primary_key = "id"
diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb
index b7cdd313a..70d2edcbd 100644
--- a/app/models/chouette/stop_area.rb
+++ b/app/models/chouette/stop_area.rb
@@ -5,6 +5,9 @@ class Chouette::StopArea < Chouette::TridentActiveRecord
# FIXME http://jira.codehaus.org/browse/JRUBY-6358
self.primary_key = "id"
include Geokit::Mappable
+ include ProjectionFields
+ include StopAreaRestrictions
+
has_many :stop_points, :dependent => :destroy
has_many :access_points, :dependent => :destroy
has_many :access_links, :dependent => :destroy
@@ -152,7 +155,7 @@ class Chouette::StopArea < Chouette::TridentActiveRecord
def default_position
# for first StopArea ... the bounds is nil :(
- Chouette::StopArea.bounds and Chouette::StopArea.bounds.center
+ Chouette::StopArea.bounds ? Chouette::StopArea.bounds.center : self.referential.envelope.center
end
def self.near(origin, distance = 0.3)
diff --git a/app/models/chouette/time_table.rb b/app/models/chouette/time_table.rb
index 033c39f1c..9af80fbb7 100644
--- a/app/models/chouette/time_table.rb
+++ b/app/models/chouette/time_table.rb
@@ -1,4 +1,5 @@
class Chouette::TimeTable < Chouette::TridentActiveRecord
+ include TimeTableRestrictions
# FIXME http://jira.codehaus.org/browse/JRUBY-6358
self.primary_key = "id"
@@ -29,6 +30,10 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord
validates_associated :dates
validates_associated :periods
+ def presenter
+ @presenter ||= ::TimeTablePresenter.new( self)
+ end
+
def self.start_validity_period
[Chouette::TimeTable.minimum(:start_date)].compact.min
end
@@ -445,6 +450,5 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord
tt.comment = I18n.t("activerecord.copy", :name => self.comment)
tt
end
-
end
diff --git a/app/models/chouette/trident_active_record.rb b/app/models/chouette/trident_active_record.rb
index b89b85863..225d7bb4b 100644
--- a/app/models/chouette/trident_active_record.rb
+++ b/app/models/chouette/trident_active_record.rb
@@ -12,10 +12,19 @@ class Chouette::TridentActiveRecord < Chouette::ActiveRecord
def self.object_id_key
model_name
end
+
+ def referential
+ @referential ||= Referential.where(:slug => Apartment::Tenant.current).first!
+ end
+
+ def hub_restricted?
+ referential.data_format == "hub"
+ end
def prefix
- "NINOXE"
+ self.referential.prefix
end
+
def prepare_auto_columns
# logger.info 'calling before_validation'
# logger.info 'start before_validation : '+self.objectid.to_s
diff --git a/app/models/chouette/vehicle_journey.rb b/app/models/chouette/vehicle_journey.rb
index 44a9f8975..17d4d952f 100644
--- a/app/models/chouette/vehicle_journey.rb
+++ b/app/models/chouette/vehicle_journey.rb
@@ -1,6 +1,6 @@
module Chouette
class VehicleJourney < TridentActiveRecord
-
+ include VehicleJourneyRestrictions
# FIXME http://jira.codehaus.org/browse/JRUBY-6358
self.primary_key = "id"
@@ -43,6 +43,11 @@ module Chouette
accepts_nested_attributes_for :vehicle_journey_at_stops, :allow_destroy => true
+
+ def presenter
+ @presenter ||= ::VehicleJourneyPresenter.new( self)
+ end
+
def transport_mode_name
# return nil if transport_mode is nil
transport_mode && Chouette::TransportMode.new( transport_mode.underscore)
diff --git a/app/models/concerns/company_restrictions.rb b/app/models/concerns/company_restrictions.rb
new file mode 100644
index 000000000..3a5f17da8
--- /dev/null
+++ b/app/models/concerns/company_restrictions.rb
@@ -0,0 +1,25 @@
+module CompanyRestrictions
+ extend ActiveSupport::Concern
+
+ included do
+ include ObjectidRestrictions
+
+ with_options if: :hub_restricted? do |g|
+ # HUB-7
+ g.validate :specific_objectid
+ # HUB-8
+ #g.validates_length_of :name, :minimum => 1, :maximum => 75
+ g.validates :name, length: { in: 1..75 }
+ # HUB-9
+ #g.validates_format_of :registration_number, :with => %r{\A[\d]{1,8}\z}
+ #g.validates_uniqueness_of :registration_number
+ g.validates :registration_number,
+ uniqueness: true,
+ length: { in: 1..8 },
+ numericality: { only_integer: true }
+ end
+ end
+ def specific_objectid
+ validate_specific_objectid(3)
+ end
+end
diff --git a/app/models/concerns/connection_link_restrictions.rb b/app/models/concerns/connection_link_restrictions.rb
new file mode 100644
index 000000000..dd10d3659
--- /dev/null
+++ b/app/models/concerns/connection_link_restrictions.rb
@@ -0,0 +1,13 @@
+module ConnectionLinkRestrictions
+ extend ActiveSupport::Concern
+
+ included do
+ include ObjectidRestrictions
+
+ with_options if: :hub_restricted? do |cl|
+ # HUB-34
+ cl.validates :link_distance, numericality: { less_than_or_equal_to: 10000.to_f }
+ end
+ end
+end
+
diff --git a/app/models/concerns/group_of_line_restrictions.rb b/app/models/concerns/group_of_line_restrictions.rb
new file mode 100644
index 000000000..a3bea08a8
--- /dev/null
+++ b/app/models/concerns/group_of_line_restrictions.rb
@@ -0,0 +1,25 @@
+module GroupOfLineRestrictions
+ extend ActiveSupport::Concern
+
+ included do
+ include ObjectidRestrictions
+
+ with_options if: :hub_restricted? do |g|
+ # HUB-11
+ g.validate :specific_objectid
+ # HUB-12
+ #g.validates_length_of :name, :minimum => 1, :maximum => 75
+ g.validates :name, length: { in: 1..75 }
+ # HUB-13
+ #g.validates_format_of :registration_number, :with => %r{\A[\d]{1,8}\z}
+ #g.validates_uniqueness_of :registration_number
+ g.validates :registration_number,
+ uniqueness: true,
+ numericality: { only_integer: true },
+ length: { in: 1..8 }
+ end
+ end
+ def specific_objectid
+ validate_specific_objectid(6)
+ end
+end
diff --git a/app/models/concerns/journey_pattern_restrictions.rb b/app/models/concerns/journey_pattern_restrictions.rb
new file mode 100644
index 000000000..e8d5d203d
--- /dev/null
+++ b/app/models/concerns/journey_pattern_restrictions.rb
@@ -0,0 +1,20 @@
+module JourneyPatternRestrictions
+ extend ActiveSupport::Concern
+
+ included do
+ include ObjectidRestrictions
+
+ with_options if: :hub_restricted? do |jp|
+ # HUB-39
+ jp.validate :specific_objectid
+ # HUB-40
+ jp.validates :registration_number, numericality: { less_than: 10 ** 8 }
+ # HUB-41
+ #jp.validates_length_of :name, :maximum => 75, :allow_blank => true, :allow_nil => true
+ jp.validates :name, length: { maximum: 75 }, allow_blank: true
+ end
+ end
+ def specific_objectid
+ validate_specific_objectid( 30)
+ end
+end
diff --git a/app/models/concerns/line_restrictions.rb b/app/models/concerns/line_restrictions.rb
new file mode 100644
index 000000000..c76d5ba19
--- /dev/null
+++ b/app/models/concerns/line_restrictions.rb
@@ -0,0 +1,29 @@
+module LineRestrictions
+ extend ActiveSupport::Concern
+
+
+ included do
+ include ObjectidRestrictions
+
+ with_options if: :hub_restricted? do |l|
+ # HUB-15
+ #l.validates_format_of :objectid, :with => %r{\A\w+:\w+:[\w]{1,14}\z}
+ l.validate :specific_objectid
+ # HUB-16
+ #l.validates_format_of :number, :with => %r{\A[\w]{1,6}\z}
+ l.validates :number, length: { in: 1..6 }, format: { with: /\A[\w]+\z/ }
+ # HUB-17 & HUB-22
+ #l.validates_length_of :name, :maximum => 75
+ l.validates :name, length: { maximum: 75 }, uniqueness: true, allow_blank: true
+ # HUB-21
+ #l.validates :registration_number, :numericality => { :less_than => 10 ** 8 }
+ l.validates :registration_number, presence: true, numericality: { less_than: 10 ** 8 }
+ # HUB-22
+ #l.validates_uniqueness_of :name, :allow_blank => true
+ end
+ end
+
+ def specific_objectid
+ validate_specific_objectid( 14)
+ end
+end
diff --git a/app/models/concerns/network_restrictions.rb b/app/models/concerns/network_restrictions.rb
new file mode 100644
index 000000000..9c5d159b6
--- /dev/null
+++ b/app/models/concerns/network_restrictions.rb
@@ -0,0 +1,25 @@
+module NetworkRestrictions
+ extend ActiveSupport::Concern
+
+ included do
+ include ObjectidRestrictions
+
+ with_options if: :hub_restricted? do |n|
+ # HUB-3
+ n.validate :specific_objectid
+ # HUB-4
+ #n.validates_length_of :name, :minimum => 1, :maximum => 75
+ n.validates :name, length: { in: 1..75 }
+ # HUB-5
+ #n.validates_format_of :registration_number, :with => %r{\A[\d]{1,8}\z}
+ #n.validates_uniqueness_of :registration_number
+ n.validates :registration_number,
+ uniqueness: true,
+ numericality: { only_integer: true },
+ length: { in: 1..8 }
+ end
+ end
+ def specific_objectid
+ validate_specific_objectid( 3)
+ end
+end
diff --git a/lib/ninoxe_extension/hub/objectid_restrictions.rb b/app/models/concerns/objectid_restrictions.rb
index 1a71b9e62..4e905bdc2 100644
--- a/lib/ninoxe_extension/hub/objectid_restrictions.rb
+++ b/app/models/concerns/objectid_restrictions.rb
@@ -1,5 +1,4 @@
-# -*- coding: utf-8 -*-
-module NinoxeExtension::Hub::ObjectidRestrictions
+module ObjectidRestrictions
extend ActiveSupport::Concern
included do
diff --git a/app/models/concerns/projection_fields.rb b/app/models/concerns/projection_fields.rb
new file mode 100644
index 000000000..2d7222f73
--- /dev/null
+++ b/app/models/concerns/projection_fields.rb
@@ -0,0 +1,60 @@
+module ProjectionFields
+ extend ActiveSupport::Concern
+
+ included do
+ #attr_accessible :projection_x,:projection_y,:projection_xy
+
+ # add projection_type set on pre-insert and pre_update action
+ before_save :set_projections
+ def set_projections
+ if ! self.coordinates.blank?
+ self.long_lat_type = 'WGS84'
+ else
+ self.long_lat_type = nil
+ end
+ end
+
+ def projection
+ if self.referential.projection_type.nil? || self.referential.projection_type.empty?
+ nil
+ else
+ self.referential.projection_type
+ end
+ end
+ @point = nil
+
+ def projection_x
+ if self.long_lat_type.nil? || self.projection.nil?
+ nil
+ else
+ @point ||= GeoRuby::SimpleFeatures::Point::from_lat_lng(Geokit::LatLng.new(self.latitude,self.longitude)).project_to(self.projection.to_i)
+ @point.x
+ end
+ end
+ def projection_y
+ if self.long_lat_type.nil? || self.projection.nil?
+ nil
+ else
+ @point ||= GeoRuby::SimpleFeatures::Point::from_lat_lng(Geokit::LatLng.new(self.latitude,self.longitude)).project_to(self.projection.to_i)
+ @point.y
+ end
+ end
+ def projection_xy
+ if self.long_lat_type.nil? || self.projection.nil?
+ nil
+ else
+ @point ||= GeoRuby::SimpleFeatures::Point::from_lat_lng(Geokit::LatLng.new(self.latitude,self.longitude)).project_to(self.projection.to_i)
+ @point.x.to_s+","+@point.y.to_s
+ end
+ end
+ def projection_x=(dummy)
+ # dummy method
+ end
+ def projection_y=(dummy)
+ # dummy method
+ end
+ def projection_xy=(dummy)
+ # dummy method
+ end
+ end
+end
diff --git a/app/models/concerns/route_restrictions.rb b/app/models/concerns/route_restrictions.rb
new file mode 100644
index 000000000..5a098d86f
--- /dev/null
+++ b/app/models/concerns/route_restrictions.rb
@@ -0,0 +1,25 @@
+module RouteRestrictions
+ extend ActiveSupport::Concern
+
+ included do
+ include ObjectidRestrictions
+ validate :max_instance_limitation, :wayback_code_limitation
+
+ # HUB-37
+ def wayback_code_limitation
+ return unless hub_restricted?
+ errors.add( :wayback_code, I18n.t('hub.routes.wayback_code_exclusive')) if line.routes.reject {|r| r.id==id}.map(&:wayback_code).include?( wayback_code)
+ end
+
+ # HUB-37
+ def max_instance_limitation
+ return unless hub_restricted?
+ errors.add( :flash, I18n.t('hub.routes.max_by_line')) if 2 < line.routes.size
+ end
+
+ # HUB-38
+ with_options if: :hub_restricted? do |route|
+ route.validates_format_of :objectid, :with => %r{\A\w+:\w+:([\w]{1,8}|__pending_id__\d+)\z}
+ end
+ end
+end
diff --git a/app/models/concerns/stop_area_restrictions.rb b/app/models/concerns/stop_area_restrictions.rb
new file mode 100644
index 000000000..38a57b55a
--- /dev/null
+++ b/app/models/concerns/stop_area_restrictions.rb
@@ -0,0 +1,63 @@
+module StopAreaRestrictions
+ extend ActiveSupport::Concern
+
+ def physical?
+ self.area_type=="BoardingPosition" || self.area_type=="Quay"
+ end
+ def commercial?
+ self.area_type=="CommercialStopPoint"
+ end
+ def physical_hub_restricted?
+ hub_restricted? && physical?
+ end
+ def commercial_hub_restricted?
+ hub_restricted? && commercial?
+ end
+ def commercial_and_physical_hub_restricted?
+ physical_hub_restricted? || commercial_hub_restricted?
+ end
+ # def specific_objectid
+ # validate_specific_objectid( 12)
+ # end
+
+ included do
+ include ObjectidRestrictions
+
+
+ with_options if: :commercial_and_physical_hub_restricted? do |sa|
+ # HUB-23
+ sa.validate :specific_objectid
+ #sa.validates_length_of :name, :minimum => 1, :maximum => 75
+ sa.validates :name, length: { in: 1..75 }
+ end
+
+ with_options if: :commercial_hub_restricted? do |sa|
+ # HUB-24
+ #sa.validates_length_of :nearest_topic_name, :maximum => 255, :allow_blank => true, :allow_nil => true
+ sa.validates :nearest_topic_name, length: { maximum: 255 }, allow_blank: true
+ end
+
+ with_options if: :physical_hub_restricted? do |sa|
+ # HUB-25
+ #sa.validates_length_of :nearest_topic_name, :maximum => 60, :allow_blank => true, :allow_nil => true
+ sa.validates :nearest_topic_name, length: { maximum: 60 }, allow_blank: true
+ # HUB-28
+ #sa.validates_presence_of :coordinates
+ sa.validates :coordinates, presence: true
+ # HUB-29
+ #sa.validates_length_of :city_name, :minimum => 1, :maximum => 80
+ sa.validates :city_name, length: { in: 1..80 }
+ # HUB-30
+ #sa.validates_format_of :country_code, :with => %r{\A[\d]{5}\z}
+ sa.validates :country_code, presence: true, numericality: { only_integer: true }, length: { is: 5 }
+ # HUB-31
+ #sa.validates_length_of :comment, :maximum => 255, :allow_blank => true, :allow_nil => true
+ sa.validates :comment, length: { maximum: 255 }, allow_blank: true
+ #sa.validates :registration_number, :numericality => { :less_than => 10 ** 8 }
+ sa.validates :registration_number, presence: true, numericality: { less_than: 10 ** 8 }
+ end
+ end
+ def specific_objectid
+ validate_specific_objectid(12)
+ end
+end
diff --git a/app/models/concerns/time_table_restrictions.rb b/app/models/concerns/time_table_restrictions.rb
new file mode 100644
index 000000000..51576833c
--- /dev/null
+++ b/app/models/concerns/time_table_restrictions.rb
@@ -0,0 +1,18 @@
+module TimeTableRestrictions
+ extend ActiveSupport::Concern
+
+ included do
+ include ObjectidRestrictions
+
+ with_options if: :hub_restricted? do |tt|
+ # HUB-44
+ tt.validate :specific_objectid
+ # HUB-45
+ #tt.validates_length_of :comment, :maximum => 75, :allow_blank => true, :allow_nil => true
+ tt.validates :comment, length: { maximum: 75 }, allow_blank: true
+ end
+ end
+ def specific_objectid
+ validate_specific_objectid( 6)
+ end
+end
diff --git a/app/models/concerns/vehicle_journey_restrictions.rb b/app/models/concerns/vehicle_journey_restrictions.rb
new file mode 100644
index 000000000..1f024eb04
--- /dev/null
+++ b/app/models/concerns/vehicle_journey_restrictions.rb
@@ -0,0 +1,15 @@
+module VehicleJourneyRestrictions
+ extend ActiveSupport::Concern
+
+ included do
+ include ObjectidRestrictions
+
+ # HUB-42
+ with_options if: :hub_restricted? do |vj|
+ vj.validate :specific_objectid
+ end
+ end
+ def specific_objectid
+ validate_specific_objectid( 8)
+ end
+end
diff --git a/app/models/referential.rb b/app/models/referential.rb
index 7c6de6bf9..1f0c5bcfd 100644
--- a/app/models/referential.rb
+++ b/app/models/referential.rb
@@ -201,81 +201,4 @@ class Referential < ActiveRecord::Base
bounds = read_attribute(:bounds)
GeoRuby::SimpleFeatures::Geometry.from_ewkt(bounds.present? ? bounds : default_bounds ).envelope
end
-
- ##
- # In Development environment where cache_classes = false
- # each time a controller rb file is saved
- # ninoxe models are reloaded without after_initialize from config/initializers
- # so for development confort, it's better to keep here that after_initialize
-Rails.application.config.after_initialize do
-
- Chouette::TridentActiveRecord
-
- class Chouette::TridentActiveRecord
-
- # add referential relationship for objectid and localization functions
- def referential
- @referential ||= Referential.where(:slug => Apartment::Tenant.current).first!
- end
-
- def hub_restricted?
- referential.data_format == "hub"
- end
-
- # override prefix for good prefix in objectid generation
- def prefix
- self.referential.prefix
- end
-
- end
-
- # Hub constraints
- Chouette::Route; class Chouette::Route; include NinoxeExtension::Hub::RouteRestrictions; end
- Chouette::JourneyPattern; class Chouette::JourneyPattern; include NinoxeExtension::Hub::JourneyPatternRestrictions; end
- Chouette::VehicleJourney; class Chouette::VehicleJourney; include NinoxeExtension::Hub::VehicleJourneyRestrictions; end
- Chouette::TimeTable; class Chouette::TimeTable; include NinoxeExtension::Hub::TimeTableRestrictions; end
- Chouette::ConnectionLink; class Chouette::ConnectionLink; include NinoxeExtension::Hub::ConnectionLinkRestrictions; end
- Chouette::StopArea; class Chouette::StopArea; include NinoxeExtension::Hub::StopAreaRestrictions; end
- Chouette::Line; class Chouette::Line; include NinoxeExtension::Hub::LineRestrictions; end
- Chouette::GroupOfLine; class Chouette::GroupOfLine; include NinoxeExtension::Hub::GroupOfLineRestrictions; end
- Chouette::Company; class Chouette::Company; include NinoxeExtension::Hub::CompanyRestrictions; end
- Chouette::Network; class Chouette::Network; include NinoxeExtension::Hub::NetworkRestrictions; end
-
- Chouette::TimeTable
-
- class Chouette::TimeTable
- def presenter
- @presenter ||= ::TimeTablePresenter.new( self)
- end
- end
-
- Chouette::VehicleJourney
-
- class Chouette::VehicleJourney
- def presenter
- @presenter ||= ::VehicleJourneyPresenter.new( self)
- end
- end
-
- Chouette::StopArea
-
- class Chouette::StopArea
- include NinoxeExtension::ProjectionFields
-
- # override default_position method to add referential envelope when no stoparea is positioned
- def default_position
- # for first StopArea ... the bounds is nil , set to referential center
- Chouette::StopArea.bounds ? Chouette::StopArea.bounds.center : self.referential.envelope.center
- end
-
-
- end
-
- Chouette::AccessPoint
-
- class Chouette::AccessPoint
- include NinoxeExtension::ProjectionFields
- end
-
-end
end
diff --git a/lib/ninoxe_extension/hub/company_restrictions.rb b/lib/ninoxe_extension/hub/company_restrictions.rb
deleted file mode 100644
index ee194a046..000000000
--- a/lib/ninoxe_extension/hub/company_restrictions.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-module NinoxeExtension::Hub
- module CompanyRestrictions
- extend ActiveSupport::Concern
-
- included do
- include ObjectidRestrictions
-
- with_options if: :hub_restricted? do |g|
- # HUB-7
- g.validate :specific_objectid
- # HUB-8
- #g.validates_length_of :name, :minimum => 1, :maximum => 75
- g.validates :name, length: { in: 1..75 }
- # HUB-9
- #g.validates_format_of :registration_number, :with => %r{\A[\d]{1,8}\z}
- #g.validates_uniqueness_of :registration_number
- g.validates :registration_number,
- uniqueness: true,
- length: { in: 1..8 },
- numericality: { only_integer: true }
- end
- end
- def specific_objectid
- validate_specific_objectid(3)
- end
- end
-end
-
diff --git a/lib/ninoxe_extension/hub/connection_link_restrictions.rb b/lib/ninoxe_extension/hub/connection_link_restrictions.rb
deleted file mode 100644
index 6d4c3046f..000000000
--- a/lib/ninoxe_extension/hub/connection_link_restrictions.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-# -*- coding: utf-8 -*-
-module NinoxeExtension::Hub
- module ConnectionLinkRestrictions
- extend ActiveSupport::Concern
-
- included do
- include ObjectidRestrictions
-
- with_options if: :hub_restricted? do |cl|
- # HUB-34
- cl.validates :link_distance, numericality: { less_than_or_equal_to: 10000.to_f }
- end
- end
- end
-end
-
diff --git a/lib/ninoxe_extension/hub/group_of_line_restrictions.rb b/lib/ninoxe_extension/hub/group_of_line_restrictions.rb
deleted file mode 100644
index 26e5c5d5c..000000000
--- a/lib/ninoxe_extension/hub/group_of_line_restrictions.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-# -*- coding: utf-8 -*-
-module NinoxeExtension::Hub
- module GroupOfLineRestrictions
- extend ActiveSupport::Concern
-
- included do
- include ObjectidRestrictions
-
- with_options if: :hub_restricted? do |g|
- # HUB-11
- g.validate :specific_objectid
- # HUB-12
- #g.validates_length_of :name, :minimum => 1, :maximum => 75
- g.validates :name, length: { in: 1..75 }
- # HUB-13
- #g.validates_format_of :registration_number, :with => %r{\A[\d]{1,8}\z}
- #g.validates_uniqueness_of :registration_number
- g.validates :registration_number,
- uniqueness: true,
- numericality: { only_integer: true },
- length: { in: 1..8 }
- end
- end
- def specific_objectid
- validate_specific_objectid(6)
- end
- end
-end
-
diff --git a/lib/ninoxe_extension/hub/journey_pattern_restrictions.rb b/lib/ninoxe_extension/hub/journey_pattern_restrictions.rb
deleted file mode 100644
index f3ec2cdbd..000000000
--- a/lib/ninoxe_extension/hub/journey_pattern_restrictions.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-# -*- coding: utf-8 -*-
-module NinoxeExtension::Hub
- module JourneyPatternRestrictions
- extend ActiveSupport::Concern
-
- included do
- include ObjectidRestrictions
-
- with_options if: :hub_restricted? do |jp|
- # HUB-39
- jp.validate :specific_objectid
- # HUB-40
- jp.validates :registration_number, numericality: { less_than: 10 ** 8 }
- # HUB-41
- #jp.validates_length_of :name, :maximum => 75, :allow_blank => true, :allow_nil => true
- jp.validates :name, length: { maximum: 75 }, allow_blank: true
- end
- end
- def specific_objectid
- validate_specific_objectid( 30)
- end
- end
-end
-
diff --git a/lib/ninoxe_extension/hub/line_restrictions.rb b/lib/ninoxe_extension/hub/line_restrictions.rb
deleted file mode 100644
index bdae3d77c..000000000
--- a/lib/ninoxe_extension/hub/line_restrictions.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-# -*- coding: utf-8 -*-
-module NinoxeExtension::Hub
- module LineRestrictions
- extend ActiveSupport::Concern
-
-
- included do
- include ObjectidRestrictions
-
- with_options if: :hub_restricted? do |l|
- # HUB-15
- #l.validates_format_of :objectid, :with => %r{\A\w+:\w+:[\w]{1,14}\z}
- l.validate :specific_objectid
- # HUB-16
- #l.validates_format_of :number, :with => %r{\A[\w]{1,6}\z}
- l.validates :number, length: { in: 1..6 }, format: { with: /\A[\w]+\z/ }
- # HUB-17 & HUB-22
- #l.validates_length_of :name, :maximum => 75
- l.validates :name, length: { maximum: 75 }, uniqueness: true, allow_blank: true
- # HUB-21
- #l.validates :registration_number, :numericality => { :less_than => 10 ** 8 }
- l.validates :registration_number, presence: true, numericality: { less_than: 10 ** 8 }
- # HUB-22
- #l.validates_uniqueness_of :name, :allow_blank => true
- end
- end
-
- def specific_objectid
- validate_specific_objectid( 14)
- end
- end
-end
-
diff --git a/lib/ninoxe_extension/hub/network_restrictions.rb b/lib/ninoxe_extension/hub/network_restrictions.rb
deleted file mode 100644
index deba1f75e..000000000
--- a/lib/ninoxe_extension/hub/network_restrictions.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-module NinoxeExtension::Hub
- module NetworkRestrictions
- extend ActiveSupport::Concern
-
- included do
- include ObjectidRestrictions
-
- with_options if: :hub_restricted? do |n|
- # HUB-3
- n.validate :specific_objectid
- # HUB-4
- #n.validates_length_of :name, :minimum => 1, :maximum => 75
- n.validates :name, length: { in: 1..75 }
- # HUB-5
- #n.validates_format_of :registration_number, :with => %r{\A[\d]{1,8}\z}
- #n.validates_uniqueness_of :registration_number
- n.validates :registration_number,
- uniqueness: true,
- numericality: { only_integer: true },
- length: { in: 1..8 }
- end
- end
- def specific_objectid
- validate_specific_objectid( 3)
- end
- end
-end
-
diff --git a/lib/ninoxe_extension/hub/route_restrictions.rb b/lib/ninoxe_extension/hub/route_restrictions.rb
deleted file mode 100644
index 6304d3559..000000000
--- a/lib/ninoxe_extension/hub/route_restrictions.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-# -*- coding: utf-8 -*-
-module NinoxeExtension::Hub
- module RouteRestrictions
- extend ActiveSupport::Concern
-
- included do
- include ObjectidRestrictions
- validate :max_instance_limitation, :wayback_code_limitation
-
- # HUB-37
- def wayback_code_limitation
- return unless hub_restricted?
- errors.add( :wayback_code, I18n.t('hub.routes.wayback_code_exclusive')) if line.routes.reject {|r| r.id==id}.map(&:wayback_code).include?( wayback_code)
- end
-
- # HUB-37
- def max_instance_limitation
- return unless hub_restricted?
- errors.add( :flash, I18n.t('hub.routes.max_by_line')) if 2 < line.routes.size
- end
-
- # HUB-38
- with_options if: :hub_restricted? do |route|
- route.validates_format_of :objectid, :with => %r{\A\w+:\w+:([\w]{1,8}|__pending_id__\d+)\z}
- end
- end
- end
-end
-
diff --git a/lib/ninoxe_extension/hub/stop_area_restrictions.rb b/lib/ninoxe_extension/hub/stop_area_restrictions.rb
deleted file mode 100644
index 17df9dba1..000000000
--- a/lib/ninoxe_extension/hub/stop_area_restrictions.rb
+++ /dev/null
@@ -1,67 +0,0 @@
-# -*- coding: utf-8 -*-
-module NinoxeExtension::Hub
- module StopAreaRestrictions
- extend ActiveSupport::Concern
-
- def physical?
- self.area_type=="BoardingPosition" || self.area_type=="Quay"
- end
- def commercial?
- self.area_type=="CommercialStopPoint"
- end
- def physical_hub_restricted?
- hub_restricted? && physical?
- end
- def commercial_hub_restricted?
- hub_restricted? && commercial?
- end
- def commercial_and_physical_hub_restricted?
- physical_hub_restricted? || commercial_hub_restricted?
- end
- # def specific_objectid
- # validate_specific_objectid( 12)
- # end
-
- included do
- include ObjectidRestrictions
-
-
- with_options if: :commercial_and_physical_hub_restricted? do |sa|
- # HUB-23
- sa.validate :specific_objectid
- #sa.validates_length_of :name, :minimum => 1, :maximum => 75
- sa.validates :name, length: { in: 1..75 }
- end
-
- with_options if: :commercial_hub_restricted? do |sa|
- # HUB-24
- #sa.validates_length_of :nearest_topic_name, :maximum => 255, :allow_blank => true, :allow_nil => true
- sa.validates :nearest_topic_name, length: { maximum: 255 }, allow_blank: true
- end
-
- with_options if: :physical_hub_restricted? do |sa|
- # HUB-25
- #sa.validates_length_of :nearest_topic_name, :maximum => 60, :allow_blank => true, :allow_nil => true
- sa.validates :nearest_topic_name, length: { maximum: 60 }, allow_blank: true
- # HUB-28
- #sa.validates_presence_of :coordinates
- sa.validates :coordinates, presence: true
- # HUB-29
- #sa.validates_length_of :city_name, :minimum => 1, :maximum => 80
- sa.validates :city_name, length: { in: 1..80 }
- # HUB-30
- #sa.validates_format_of :country_code, :with => %r{\A[\d]{5}\z}
- sa.validates :country_code, presence: true, numericality: { only_integer: true }, length: { is: 5 }
- # HUB-31
- #sa.validates_length_of :comment, :maximum => 255, :allow_blank => true, :allow_nil => true
- sa.validates :comment, length: { maximum: 255 }, allow_blank: true
- #sa.validates :registration_number, :numericality => { :less_than => 10 ** 8 }
- sa.validates :registration_number, presence: true, numericality: { less_than: 10 ** 8 }
- end
- end
- def specific_objectid
- validate_specific_objectid(12)
- end
- end
-end
-
diff --git a/lib/ninoxe_extension/hub/time_table_restrictions.rb b/lib/ninoxe_extension/hub/time_table_restrictions.rb
deleted file mode 100644
index b61d1e05a..000000000
--- a/lib/ninoxe_extension/hub/time_table_restrictions.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-# -*- coding: utf-8 -*-
-module NinoxeExtension::Hub
- module TimeTableRestrictions
- extend ActiveSupport::Concern
-
- included do
- include ObjectidRestrictions
-
- with_options if: :hub_restricted? do |tt|
- # HUB-44
- tt.validate :specific_objectid
- # HUB-45
- #tt.validates_length_of :comment, :maximum => 75, :allow_blank => true, :allow_nil => true
- tt.validates :comment, length: { maximum: 75 }, allow_blank: true
- end
- end
- def specific_objectid
- validate_specific_objectid( 6)
- end
- end
-end
-
diff --git a/lib/ninoxe_extension/hub/vehicle_journey_restrictions.rb b/lib/ninoxe_extension/hub/vehicle_journey_restrictions.rb
deleted file mode 100644
index b1a493207..000000000
--- a/lib/ninoxe_extension/hub/vehicle_journey_restrictions.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# -*- coding: utf-8 -*-
-module NinoxeExtension::Hub
- module VehicleJourneyRestrictions
- extend ActiveSupport::Concern
-
- included do
- include ObjectidRestrictions
-
- # HUB-42
- with_options if: :hub_restricted? do |vj|
- vj.validate :specific_objectid
- end
- end
- def specific_objectid
- validate_specific_objectid( 8)
- end
- end
-end
-
diff --git a/lib/ninoxe_extension/projection_fields.rb b/lib/ninoxe_extension/projection_fields.rb
deleted file mode 100644
index 25d30df94..000000000
--- a/lib/ninoxe_extension/projection_fields.rb
+++ /dev/null
@@ -1,63 +0,0 @@
-
- module NinoxeExtension::ProjectionFields
- extend ActiveSupport::Concern
-
- included do
- #attr_accessible :projection_x,:projection_y,:projection_xy
-
- # add projection_type set on pre-insert and pre_update action
- before_save :set_projections
- def set_projections
- if ! self.coordinates.blank?
- self.long_lat_type = 'WGS84'
- else
- self.long_lat_type = nil
- end
- end
-
- def projection
- if self.referential.projection_type.nil? || self.referential.projection_type.empty?
- nil
- else
- self.referential.projection_type
- end
- end
- @point = nil
-
- def projection_x
- if self.long_lat_type.nil? || self.projection.nil?
- nil
- else
- @point ||= GeoRuby::SimpleFeatures::Point::from_lat_lng(Geokit::LatLng.new(self.latitude,self.longitude)).project_to(self.projection.to_i)
- @point.x
- end
- end
- def projection_y
- if self.long_lat_type.nil? || self.projection.nil?
- nil
- else
- @point ||= GeoRuby::SimpleFeatures::Point::from_lat_lng(Geokit::LatLng.new(self.latitude,self.longitude)).project_to(self.projection.to_i)
- @point.y
- end
- end
- def projection_xy
- if self.long_lat_type.nil? || self.projection.nil?
- nil
- else
- @point ||= GeoRuby::SimpleFeatures::Point::from_lat_lng(Geokit::LatLng.new(self.latitude,self.longitude)).project_to(self.projection.to_i)
- @point.x.to_s+","+@point.y.to_s
- end
- end
- def projection_x=(dummy)
- # dummy method
- end
- def projection_y=(dummy)
- # dummy method
- end
- def projection_xy=(dummy)
- # dummy method
- end
- end
- end
-
-
diff --git a/spec/models/chouette/stop_area_spec.rb b/spec/models/chouette/stop_area_spec.rb
index b237f08ef..3b19aa17c 100644
--- a/spec/models/chouette/stop_area_spec.rb
+++ b/spec/models/chouette/stop_area_spec.rb
@@ -243,9 +243,9 @@ describe Chouette::StopArea, :type => :model do
describe "#default_position" do
- it "should return nil when StopArea.bounds is nil" do
+ it "should return referential center point when StopArea.bounds is nil" do
allow(Chouette::StopArea).to receive_messages :bounds => nil
- expect(subject.default_position).to be_nil
+ expect(subject.default_position).not_to be_nil
end
it "should return StopArea.bounds center" do
diff --git a/spec/models/chouette/trident_active_record_spec.rb b/spec/models/chouette/trident_active_record_spec.rb
index 9728a2923..654dd6685 100644
--- a/spec/models/chouette/trident_active_record_spec.rb
+++ b/spec/models/chouette/trident_active_record_spec.rb
@@ -31,31 +31,31 @@ describe Chouette::TridentActiveRecord, :type => :model do
describe "#prepare_auto_columns" do
it "should left objectid" do
- tm = Chouette::TimeTable.new :comment => "merge1" , :objectid => "NINOXE:Timetable:merge1"
+ tm = Chouette::TimeTable.new :comment => "merge1" , :objectid => "first:Timetable:merge1"
tm.prepare_auto_columns
- expect(tm.objectid).to eq("NINOXE:Timetable:merge1")
+ expect(tm.objectid).to eq("first:Timetable:merge1")
end
it "should add pending_id to objectid" do
tm = Chouette::TimeTable.new :comment => "merge1"
tm.prepare_auto_columns
- expect(tm.objectid.start_with?("NINOXE:Timetable:__pending_id__")).to be_truthy
+ expect(tm.objectid.start_with?("first:Timetable:__pending_id__")).to be_truthy
end
it "should set id to objectid" do
tm = Chouette::TimeTable.new :comment => "merge1"
tm.save
- expect(tm.objectid).to eq("NINOXE:Timetable:"+tm.id.to_s)
+ expect(tm.objectid).to eq("first:Timetable:"+tm.id.to_s)
end
it "should detect objectid conflicts" do
tm = Chouette::TimeTable.new :comment => "merge1"
tm.save
- tm.objectid = "NINOXE:Timetable:"+(tm.id+1).to_s
+ tm.objectid = "first:Timetable:"+(tm.id+1).to_s
tm.save
tm = Chouette::TimeTable.new :comment => "merge1"
tm.save
- expect(tm.objectid).to eq("NINOXE:Timetable:"+tm.id.to_s+"_1")
+ expect(tm.objectid).to eq("first:Timetable:"+tm.id.to_s+"_1")
end
end
@@ -65,48 +65,48 @@ describe Chouette::TridentActiveRecord, :type => :model do
it "should build automatic objectid when empty" do
g1 = Chouette::GroupOfLine.new( :name => "g1")
g1.save
- expect(g1.objectid).to eq("NINOXE:GroupOfLine:"+g1.id.to_s)
+ expect(g1.objectid).to eq("first:GroupOfLine:"+g1.id.to_s)
end
it "should build automatic objectid with fixed when only suffix given" do
g1 = Chouette::GroupOfLine.new( :name => "g1")
g1.objectid = "toto"
g1.save
- expect(g1.objectid).to eq("NINOXE:GroupOfLine:toto")
+ expect(g1.objectid).to eq("first:GroupOfLine:toto")
end
it "should build automatic objectid with extension when already exists" do
g1 = Chouette::GroupOfLine.new( :name => "g1")
g1.save
cnt = g1.id + 1
- g1.objectid = "NINOXE:GroupOfLine:"+cnt.to_s
+ g1.objectid = "first:GroupOfLine:"+cnt.to_s
g1.save
g2 = Chouette::GroupOfLine.new( :name => "g2")
g2.save
- expect(g2.objectid).to eq("NINOXE:GroupOfLine:"+g2.id.to_s+"_1")
+ expect(g2.objectid).to eq("first:GroupOfLine:"+g2.id.to_s+"_1")
end
it "should build automatic objectid with extension when already exists" do
g1 = Chouette::GroupOfLine.new( :name => "g1")
g1.save
cnt = g1.id + 2
- g1.objectid = "NINOXE:GroupOfLine:"+cnt.to_s
+ g1.objectid = "first:GroupOfLine:"+cnt.to_s
g1.save
g2 = Chouette::GroupOfLine.new( :name => "g2")
- g2.objectid = "NINOXE:GroupOfLine:"+cnt.to_s+"_1"
+ g2.objectid = "first:GroupOfLine:"+cnt.to_s+"_1"
g2.save
g3 = Chouette::GroupOfLine.new( :name => "g3")
g3.save
- expect(g3.objectid).to eq("NINOXE:GroupOfLine:"+g3.id.to_s+"_2")
+ expect(g3.objectid).to eq("first:GroupOfLine:"+g3.id.to_s+"_2")
end
it "should build automatic objectid when id cleared" do
g1 = Chouette::GroupOfLine.new( :name => "g1")
- g1.objectid = "NINOXE:GroupOfLine:xxxx"
+ g1.objectid = "first:GroupOfLine:xxxx"
g1.save
g1.objectid = nil
g1.save
- expect(g1.objectid).to eq("NINOXE:GroupOfLine:"+g1.id.to_s)
+ expect(g1.objectid).to eq("first:GroupOfLine:"+g1.id.to_s)
end
end