aboutsummaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
authorLuc Donnet2017-10-16 23:52:06 +0200
committerLuc Donnet2017-10-16 23:52:06 +0200
commitf480ad0739e5c0ec2c0c8bb890344b9c4777ba35 (patch)
treea19bc6b43449b8b978a53c33476fb3eb571d4dda /app/models
parentb611a84ed724036c4929bd4c3eaa7e23ea314f45 (diff)
parent51a1ea5b141032121913f807a162d305828bec54 (diff)
downloadchouette-core-f480ad0739e5c0ec2c0c8bb890344b9c4777ba35.tar.bz2
Merge branch 'master' into staging
Diffstat (limited to 'app/models')
-rw-r--r--app/models/chouette/line.rb6
-rw-r--r--app/models/chouette/time_table.rb4
-rw-r--r--app/models/chouette/transport_mode.rb71
-rw-r--r--app/models/chouette/vehicle_journey.rb2
-rw-r--r--app/models/compliance_check.rb9
-rw-r--r--app/models/compliance_check_block.rb2
-rw-r--r--app/models/compliance_check_message.rb7
-rw-r--r--app/models/compliance_check_resource.rb6
-rw-r--r--app/models/compliance_check_set.rb11
-rw-r--r--app/models/compliance_control.rb74
-rw-r--r--app/models/compliance_control_block.rb12
-rw-r--r--app/models/compliance_control_set.rb7
-rw-r--r--app/models/concerns/min_max_values_validation.rb13
-rw-r--r--app/models/concerns/stif_netex_attributes_support.rb2
-rw-r--r--app/models/concerns/stif_transport_mode_enumerations.rb18
-rw-r--r--app/models/concerns/stif_transport_submode_enumerations.rb24
-rw-r--r--app/models/dashboard.rb27
-rw-r--r--app/models/generic_attribute_control/min_max.rb16
-rw-r--r--app/models/generic_attribute_control/pattern.rb14
-rw-r--r--app/models/generic_attribute_control/uniqueness.rb13
-rw-r--r--app/models/generic_attribute_min_max.rb27
-rw-r--r--app/models/generic_attribute_pattern.rb23
-rw-r--r--app/models/generic_attribute_uniqueness.rb23
-rw-r--r--app/models/import.rb4
-rw-r--r--app/models/journey_pattern_control/duplicates.rb9
-rw-r--r--app/models/journey_pattern_control/vehicle_journey.rb11
-rw-r--r--app/models/line_control/route.rb11
-rw-r--r--app/models/line_referential.rb6
-rw-r--r--app/models/organisation.rb10
-rw-r--r--app/models/route_control/duplicates.rb9
-rw-r--r--app/models/route_control/journey_pattern.rb11
-rw-r--r--app/models/route_control/minimum_length.rb9
-rw-r--r--app/models/route_control/omnibus_journey_pattern.rb9
-rw-r--r--app/models/route_control/opposite_route.rb10
-rw-r--r--app/models/route_control/opposite_route_terminus.rb11
-rw-r--r--app/models/route_control/speed.rb15
-rw-r--r--app/models/route_control/stop_points_in_journey_pattern.rb11
-rw-r--r--app/models/route_control/time_table.rb13
-rw-r--r--app/models/route_control/unactivated_stop_points.rb11
-rw-r--r--app/models/route_control/vehicle_journey_at_stops.rb13
-rw-r--r--app/models/route_control/zdl_stop_area.rb9
-rw-r--r--app/models/routing_constaint_zone_control/maximum_length.rb13
-rw-r--r--app/models/routing_constaint_zone_control/minimum_length.rb13
-rw-r--r--app/models/routing_constaint_zone_control/unactivated_stop_point.rb13
-rw-r--r--app/models/routing_constraint_zone_control/maximum_length.rb6
-rw-r--r--app/models/routing_constraint_zone_control/minimum_length.rb6
-rw-r--r--app/models/routing_constraint_zone_control/unactivated_stop_point.rb6
-rw-r--r--app/models/rule_parameter_set.rb21
-rw-r--r--app/models/stif_transport_mode_enumerations.rb5
-rw-r--r--app/models/vechicle_journey_control/delta.rb15
-rw-r--r--app/models/vechicle_journey_control/waiting_time.rb13
-rw-r--r--app/models/vehicle_journey_control/delta.rb10
-rw-r--r--app/models/vehicle_journey_control/speed.rb11
-rw-r--r--app/models/vehicle_journey_control/time_table.rb6
-rw-r--r--app/models/vehicle_journey_control/vehicle_journey_at_stops.rb6
-rw-r--r--app/models/vehicle_journey_control/waiting_time.rb9
-rw-r--r--app/models/vehicle_journey_import.rb2
-rw-r--r--app/models/workbench.rb14
58 files changed, 373 insertions, 389 deletions
diff --git a/app/models/chouette/line.rb b/app/models/chouette/line.rb
index 63d2d1606..0139bb6a4 100644
--- a/app/models/chouette/line.rb
+++ b/app/models/chouette/line.rb
@@ -2,13 +2,11 @@ class Chouette::Line < Chouette::ActiveRecord
include StifCodifligneAttributesSupport
include LineRestrictions
include LineReferentialSupport
- include StifTransportModeEnumerations
+ extend StifTransportModeEnumerations
+ extend StifTransportSubmodeEnumerations
- extend Enumerize
extend ActiveModel::Naming
- enumerize :transport_submode, in: %i(unknown undefined internationalFlight domesticFlight intercontinentalFlight domesticScheduledFlight shuttleFlight intercontinentalCharterFlight internationalCharterFlight roundTripCharterFlight sightseeingFlight helicopterService domesticCharterFlight SchengenAreaFlight airshipService shortHaulInternationalFlight canalBarge localBus regionalBus expressBus nightBus postBus specialNeedsBus mobilityBus mobilityBusForRegisteredDisabled sightseeingBus shuttleBus highFrequencyBus dedicatedLaneBus schoolBus schoolAndPublicServiceBus railReplacementBus demandAndResponseBus airportLinkBus internationalCoach nationalCoach shuttleCoach regionalCoach specialCoach schoolCoach sightseeingCoach touristCoach commuterCoach metro tube urbanRailway local highSpeedRail suburbanRailway regionalRail interregionalRail longDistance intermational sleeperRailService nightRail carTransportRailService touristRailway railShuttle replacementRailService specialTrain crossCountryRail rackAndPinionRailway cityTram localTram regionalTram sightseeingTram shuttleTram trainTram internationalCarFerry nationalCarFerry regionalCarFerry localCarFerry internationalPassengerFerry nationalPassengerFerry regionalPassengerFerry localPassengerFerry postBoat trainFerry roadFerryLink airportBoatLink highSpeedVehicleService highSpeedPassengerService sightseeingService schoolBoat cableFerry riverBus scheduledFerry shuttleFerryService telecabin cableCar lift chairLift dragLift telecabinLink funicular streetCableCar allFunicularServices undefinedFunicular)
-
# FIXME http://jira.codehaus.org/browse/JRUBY-6358
self.primary_key = "id"
diff --git a/app/models/chouette/time_table.rb b/app/models/chouette/time_table.rb
index 8821a5201..72496273e 100644
--- a/app/models/chouette/time_table.rb
+++ b/app/models/chouette/time_table.rb
@@ -21,12 +21,12 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord
belongs_to :calendar
belongs_to :created_from, class_name: 'Chouette::TimeTable'
- scope :overlapping, -> (date_start, date_end) do
+ scope :overlapping, -> (period_range) do
joins("
LEFT JOIN time_table_periods ON time_tables.id = time_table_periods.time_table_id
LEFT JOIN time_table_dates ON time_tables.id = time_table_dates.time_table_id
")
- .where("(time_table_periods.period_start <= :end AND time_table_periods.period_end >= :start) OR (time_table_dates.date BETWEEN :start AND :end)", {start: date_start, end: date_end})
+ .where("(time_table_periods.period_start <= :end AND time_table_periods.period_end >= :begin) OR (time_table_dates.date BETWEEN :begin AND :end)", {begin: period_range.begin, end: period_range.end})
end
after_save :save_shortcuts
diff --git a/app/models/chouette/transport_mode.rb b/app/models/chouette/transport_mode.rb
deleted file mode 100644
index 825ef15b8..000000000
--- a/app/models/chouette/transport_mode.rb
+++ /dev/null
@@ -1,71 +0,0 @@
-class Chouette::TransportMode < ActiveSupport::StringInquirer
-
- def initialize(text_code, numerical_code)
- super text_code.to_s
- @numerical_code = numerical_code
- end
-
- def self.new(text_code, numerical_code = nil)
- if text_code and numerical_code
- super
- elsif self === text_code
- text_code
- else
- if Fixnum === text_code
- text_code, numerical_code = definitions.rassoc(text_code)
- else
- text_code, numerical_code = definitions.assoc(text_code.to_s)
- end
-
- super text_code, numerical_code
- end
- end
-
- def to_i
- @numerical_code
- end
-
- def inspect
- "#{to_s}/#{to_i}"
- end
-
- def name
- camelize
- end
-
- @@definitions = [
- ["interchange", -1],
- ["unknown", 0],
- ["coach", 1],
- ["air", 2],
- ["waterborne", 3],
- ["bus", 4],
- ["ferry", 5],
- ["walk", 6],
- ["metro", 7],
- ["shuttle", 8],
- ["rapid_transit", 9],
- ["taxi", 10],
- ["local_train", 11],
- ["train", 12],
- ["long_distance_train", 13],
- ["tramway", 14],
- ["trolleybus", 15],
- ["private_vehicle", 16],
- ["bicycle", 17],
- ["other", 18]
- ]
- cattr_reader :definitions
-
- @@all = nil
- def self.all
- @@all ||= definitions.collect do |text_code, numerical_code|
- new(text_code, numerical_code)
- end
- end
-
- def public_transport?
- not interchange?
- end
-
-end
diff --git a/app/models/chouette/vehicle_journey.rb b/app/models/chouette/vehicle_journey.rb
index f574afc93..e534d2bde 100644
--- a/app/models/chouette/vehicle_journey.rb
+++ b/app/models/chouette/vehicle_journey.rb
@@ -2,7 +2,7 @@ module Chouette
class VehicleJourney < TridentActiveRecord
include ChecksumSupport
include VehicleJourneyRestrictions
- include StifTransportModeEnumerations
+ extend StifTransportModeEnumerations
# FIXME http://jira.codehaus.org/browse/JRUBY-6358
self.primary_key = "id"
diff --git a/app/models/compliance_check.rb b/app/models/compliance_check.rb
index 85cf5e37e..55f2ae228 100644
--- a/app/models/compliance_check.rb
+++ b/app/models/compliance_check.rb
@@ -1,9 +1,14 @@
class ComplianceCheck < ActiveRecord::Base
+
+ self.inheritance_column = nil
+
+ extend Enumerize
belongs_to :compliance_check_set
belongs_to :compliance_check_block
-
- enum criticity: [:info, :warning, :error]
+
+ enumerize :criticity, in: %i(warning error), scope: true, default: :warning
validates :criticity, presence: true
validates :name, presence: true
validates :code, presence: true
+ validates :origin_code, presence: true
end
diff --git a/app/models/compliance_check_block.rb b/app/models/compliance_check_block.rb
index 035c03ed9..ee60a8bb1 100644
--- a/app/models/compliance_check_block.rb
+++ b/app/models/compliance_check_block.rb
@@ -1,3 +1,5 @@
class ComplianceCheckBlock < ActiveRecord::Base
belongs_to :compliance_check_set
+
+ has_many :compliance_checks
end
diff --git a/app/models/compliance_check_message.rb b/app/models/compliance_check_message.rb
index 86899eb15..738bd4a4b 100644
--- a/app/models/compliance_check_message.rb
+++ b/app/models/compliance_check_message.rb
@@ -1,4 +1,11 @@
class ComplianceCheckMessage < ActiveRecord::Base
+ extend Enumerize
+
+ belongs_to :compliance_check_set
belongs_to :compliance_check
belongs_to :compliance_check_resource
+
+ enumerize :status, in: %i(OK ERROR WARNING IGNORED), scope: true
+
+ validates_presence_of :compliance_check_set
end
diff --git a/app/models/compliance_check_resource.rb b/app/models/compliance_check_resource.rb
index 7826f00c3..2989bf3cf 100644
--- a/app/models/compliance_check_resource.rb
+++ b/app/models/compliance_check_resource.rb
@@ -1,5 +1,9 @@
class ComplianceCheckResource < ActiveRecord::Base
extend Enumerize
- enumerize :status, in: %w[new successful warning failed]
+ belongs_to :compliance_check_set
+
+ enumerize :status, in: %i(OK ERROR WARNING IGNORED), scope: true
+
+ validates_presence_of :compliance_check_set
end
diff --git a/app/models/compliance_check_set.rb b/app/models/compliance_check_set.rb
index 7b6400a21..536afc705 100644
--- a/app/models/compliance_check_set.rb
+++ b/app/models/compliance_check_set.rb
@@ -6,5 +6,16 @@ class ComplianceCheckSet < ActiveRecord::Base
belongs_to :workbench
belongs_to :parent, polymorphic: true
+ has_many :compliance_check_blocks
+ has_many :compliance_checks
+
+ has_many :compliance_check_resources
+ has_many :compliance_check_messages
+
enumerize :status, in: %w[new pending successful warning failed running aborted canceled]
+
+ scope :where_created_at_between, ->(period_range) do
+ where('created_at BETWEEN :begin AND :end', begin: period_range.begin, end: period_range.end)
+ end
+
end
diff --git a/app/models/compliance_control.rb b/app/models/compliance_control.rb
index 12ff4737a..baf491e8a 100644
--- a/app/models/compliance_control.rb
+++ b/app/models/compliance_control.rb
@@ -1,12 +1,80 @@
class ComplianceControl < ActiveRecord::Base
+ extend Enumerize
belongs_to :compliance_control_set
belongs_to :compliance_control_block
- extend Enumerize
- enumerize :criticity, in: %i(info warning error), scope: true, default: :info
+ enumerize :criticity, in: %i(warning error), scope: true, default: :warning
+ hstore_accessor :control_attributes, {}
validates :criticity, presence: true
validates :name, presence: true
- validates :code, presence: true
+ validates :code, presence: true, uniqueness: { scope: :compliance_control_set }
+ validates :origin_code, presence: true
validates :compliance_control_set, presence: true
+
+ validate def coherent_control_set
+ return true if compliance_control_block_id.nil?
+ ids = [compliance_control_block.compliance_control_set_id, compliance_control_set_id]
+ return true if ids.first == ids.last
+ names = ids.map{|id| ComplianceControlSet.find(id).name}
+ errors.add(:coherent_control_set,
+ I18n.t('compliance_controls.errors.incoherent_control_sets',
+ indirect_set_name: names.first,
+ direct_set_name: names.last))
+ end
+
+ class << self
+ def default_criticity; :warning end
+ def default_code; "" end
+ def dynamic_attributes
+ hstore_metadata_for_control_attributes.keys
+ end
+
+ def policy_class
+ ComplianceControlPolicy
+ end
+
+ def inherited(child)
+ child.instance_eval do
+ def model_name
+ ComplianceControl.model_name
+ end
+ end
+ super
+ end
+ end
+
+ def initialize(attributes = {})
+ super
+ self.name ||= I18n.t("activerecord.models.#{self.class.name.underscore}.one")
+ self.code ||= self.class.default_code
+ self.origin_code ||= self.class.default_code
+ end
+
end
+
+# Ensure STI subclasses are loaded
+# http://guides.rubyonrails.org/autoloading_and_reloading_constants.html#autoloading-and-sti
+require_dependency 'generic_attribute_control/min_max'
+require_dependency 'generic_attribute_control/pattern'
+require_dependency 'generic_attribute_control/uniqueness'
+require_dependency 'journey_pattern_control/duplicates'
+require_dependency 'journey_pattern_control/vehicle_journey'
+require_dependency 'line_control/route'
+require_dependency 'route_control/duplicates'
+require_dependency 'route_control/journey_pattern'
+require_dependency 'route_control/minimum_length'
+require_dependency 'route_control/omnibus_journey_pattern'
+require_dependency 'route_control/opposite_route_terminus'
+require_dependency 'route_control/opposite_route'
+require_dependency 'route_control/stop_points_in_journey_pattern'
+require_dependency 'route_control/unactivated_stop_points'
+require_dependency 'route_control/zdl_stop_area'
+require_dependency 'routing_constraint_zone_control/maximum_length'
+require_dependency 'routing_constraint_zone_control/minimum_length'
+require_dependency 'routing_constraint_zone_control/unactivated_stop_point'
+require_dependency 'vehicle_journey_control/delta'
+require_dependency 'vehicle_journey_control/waiting_time'
+require_dependency 'vehicle_journey_control/speed'
+require_dependency 'vehicle_journey_control/time_table'
+require_dependency 'vehicle_journey_control/vehicle_journey_at_stops'
diff --git a/app/models/compliance_control_block.rb b/app/models/compliance_control_block.rb
index cf5a9d72b..5721c00f4 100644
--- a/app/models/compliance_control_block.rb
+++ b/app/models/compliance_control_block.rb
@@ -1,3 +1,15 @@
class ComplianceControlBlock < ActiveRecord::Base
+ extend StifTransportModeEnumerations
+ extend StifTransportSubmodeEnumerations
+
belongs_to :compliance_control_set
+ has_many :compliance_controls, dependent: :destroy
+
+ hstore_accessor :condition_attributes,
+ transport_mode: :string,
+ transport_submode: :string
+
+ validates :transport_mode, presence: true
+ validates :compliance_control_set, presence: true
+
end
diff --git a/app/models/compliance_control_set.rb b/app/models/compliance_control_set.rb
index cefdfbf1f..deb46f5a1 100644
--- a/app/models/compliance_control_set.rb
+++ b/app/models/compliance_control_set.rb
@@ -1,7 +1,12 @@
class ComplianceControlSet < ActiveRecord::Base
belongs_to :organisation
- has_many :compliance_controls
+ has_many :compliance_control_blocks, dependent: :destroy
+ has_many :compliance_controls, dependent: :destroy
validates :name, presence: true
+ validates :organisation, presence: true
+ scope :where_updated_at_between, ->(period_range) do
+ where('updated_at BETWEEN :begin AND :end', begin: period_range.begin, end: period_range.end)
+ end
end
diff --git a/app/models/concerns/min_max_values_validation.rb b/app/models/concerns/min_max_values_validation.rb
new file mode 100644
index 000000000..c177e55ca
--- /dev/null
+++ b/app/models/concerns/min_max_values_validation.rb
@@ -0,0 +1,13 @@
+module MinMaxValuesValidation
+ extend ActiveSupport::Concern
+
+ included do
+ validate :min_max_values_validation
+ end
+
+ def min_max_values_validation
+ return true unless minimum && maximum
+ return true unless maximum < minimum
+ errors.add(:min_max_values, I18n.t('compliance_controls.min_max_values', min: minimum, max: maximum))
+ end
+end
diff --git a/app/models/concerns/stif_netex_attributes_support.rb b/app/models/concerns/stif_netex_attributes_support.rb
index 0d569b613..076acf491 100644
--- a/app/models/concerns/stif_netex_attributes_support.rb
+++ b/app/models/concerns/stif_netex_attributes_support.rb
@@ -49,7 +49,7 @@ module StifNetexAttributesSupport
end
def provider_id
- self.referential.workbench.organisation.name.parameterize.underscore
+ self.referential.workbench.organisation.code.underscore.parameterize
end
def boiv_id
diff --git a/app/models/concerns/stif_transport_mode_enumerations.rb b/app/models/concerns/stif_transport_mode_enumerations.rb
new file mode 100644
index 000000000..68d481735
--- /dev/null
+++ b/app/models/concerns/stif_transport_mode_enumerations.rb
@@ -0,0 +1,18 @@
+module StifTransportModeEnumerations
+ extend ActiveSupport::Concern
+ extend Enumerize
+ extend self
+
+ enumerize :transport_mode, in: %w(bus
+ metro
+ rail
+ tram)
+
+ def transport_modes
+ StifTransportModeEnumerations.transport_mode.values
+ end
+
+ def sorted_transport_modes
+ self.transport_modes.sort_by{|m| I18n.t("enumerize.transport_mode.#{m}").parameterize }
+ end
+end
diff --git a/app/models/concerns/stif_transport_submode_enumerations.rb b/app/models/concerns/stif_transport_submode_enumerations.rb
new file mode 100644
index 000000000..cf314badd
--- /dev/null
+++ b/app/models/concerns/stif_transport_submode_enumerations.rb
@@ -0,0 +1,24 @@
+module StifTransportSubmodeEnumerations
+ extend ActiveSupport::Concern
+ extend Enumerize
+ extend self
+
+ enumerize :transport_submode, in: %w(demandAndResponseBus
+ nightBus
+ airportLinkBus
+ highFrequencyBus
+ expressBus
+ railShuttle
+ suburbanRailway
+ regionalRail
+ interregionalRail
+)
+
+ def transport_submodes
+ StifTransportSubmodeEnumerations.transport_submode.values
+ end
+
+ def sorted_transport_submodes
+ self.transport_submodes.sort_by{|m| I18n.t("enumerize.transport_submode.#{m}").parameterize }
+ end
+end
diff --git a/app/models/dashboard.rb b/app/models/dashboard.rb
new file mode 100644
index 000000000..a53267db5
--- /dev/null
+++ b/app/models/dashboard.rb
@@ -0,0 +1,27 @@
+#
+# The default Dashboard implementation can be customized in an initializer :
+#
+# Rails.application.config.to_prepare do
+# Dashboard.default_class = Custom::Dashboard
+# end
+#
+class Dashboard
+ include ActiveModel::Conversion
+
+ @@default_class = self
+ mattr_accessor :default_class
+
+ attr_reader :context
+
+ def initialize(context)
+ @context = context
+ end
+
+ def self.create(context)
+ default_class.new context
+ end
+
+ def current_organisation
+ context.send(:current_organisation)
+ end
+end
diff --git a/app/models/generic_attribute_control/min_max.rb b/app/models/generic_attribute_control/min_max.rb
new file mode 100644
index 000000000..a83ab64ab
--- /dev/null
+++ b/app/models/generic_attribute_control/min_max.rb
@@ -0,0 +1,16 @@
+module GenericAttributeControl
+ class MinMax < ComplianceControl
+ hstore_accessor :control_attributes, minimum: :integer, maximum: :integer, target: :string
+
+ validates :minimum, numericality: true, allow_nil: true
+ validates :maximum, numericality: true, allow_nil: true
+ validates :target, presence: true
+ include MinMaxValuesValidation
+
+ class << self
+ def attribute_type; :integer end
+ def default_criticity; :warning end
+ def default_code; "3-Generic-2" end
+ end
+ end
+end
diff --git a/app/models/generic_attribute_control/pattern.rb b/app/models/generic_attribute_control/pattern.rb
new file mode 100644
index 000000000..027d6948e
--- /dev/null
+++ b/app/models/generic_attribute_control/pattern.rb
@@ -0,0 +1,14 @@
+module GenericAttributeControl
+ class Pattern < ComplianceControl
+ hstore_accessor :control_attributes, pattern: :string, target: :string
+
+ validates :target, presence: true
+ validates :pattern, presence: true
+
+ class << self
+ def attribute_type; :string end
+ def default_criticity; :warning end
+ def default_code; "3-Generic-1" end
+ end
+ end
+end
diff --git a/app/models/generic_attribute_control/uniqueness.rb b/app/models/generic_attribute_control/uniqueness.rb
new file mode 100644
index 000000000..36a270d74
--- /dev/null
+++ b/app/models/generic_attribute_control/uniqueness.rb
@@ -0,0 +1,13 @@
+module GenericAttributeControl
+ class Uniqueness < ComplianceControl
+ hstore_accessor :control_attributes, target: :string
+
+ validates :target, presence: true
+
+ class << self
+ def attribute_type; :string end
+ def default_criticity; :warning end
+ def default_code; "3-Generic-3" end
+ end
+ end
+end
diff --git a/app/models/generic_attribute_min_max.rb b/app/models/generic_attribute_min_max.rb
deleted file mode 100644
index e9a127c56..000000000
--- a/app/models/generic_attribute_min_max.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-#module ComplianceControls
-
- class GenericAttributeMinMax < ComplianceControl
-
-
- hstore_accessor :control_attributes, minimum: :integer, maximum: :integer
- #attribute :minimum, type: :integer, optionnal: true
- #attribute :maximum, type: :integer, optionnal: true
- # #attribute :target, type: ModelAttribute
-
- @@default_criticity = :warning
- @@default_code = "3-Generic-2"
-
- validate :min_max_values
- def min_max_values
- true
- end
-
- after_initialize do
- self.name = 'GenericAttributeMinMax'
- self.code = @@default_code
- self.criticity = @@default_criticity
- end
-
- end
-
-#end
diff --git a/app/models/generic_attribute_pattern.rb b/app/models/generic_attribute_pattern.rb
deleted file mode 100644
index 0043f1563..000000000
--- a/app/models/generic_attribute_pattern.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-#module ComplianceControls
-
- class GenericAttributePattern < ComplianceControl
-
- hstore_accessor :control_attributes, value: :string, pattern: :string
-
- @@default_criticity = :warning
- @@default_code = "3-Generic-3"
-
- validate :pattern_match
- def pattern_match
- true
- end
-
- after_initialize do
- self.name = 'GenericAttributeMinMax'
- self.code = @@default_code
- self.criticity = @@default_criticity
- end
-
- end
-
-#end \ No newline at end of file
diff --git a/app/models/generic_attribute_uniqueness.rb b/app/models/generic_attribute_uniqueness.rb
deleted file mode 100644
index dcf4a16c2..000000000
--- a/app/models/generic_attribute_uniqueness.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-#module ComplianceControls
-
- class GenericAttributeUniqueness < ComplianceControl
-
- hstore_accessor :control_attributes, name: :string
-
- @@default_criticity = :warning
- @@default_code = "3-Generic-3"
-
- validate :unique_values
- def unique_values
- true
- end
-
- after_initialize do
- self.name = 'GenericAttributeMinMax'
- self.code = @@default_code
- self.criticity = @@default_criticity
- end
-
- end
-
-#end \ No newline at end of file
diff --git a/app/models/import.rb b/app/models/import.rb
index 74f7ef10c..64f713914 100644
--- a/app/models/import.rb
+++ b/app/models/import.rb
@@ -9,8 +9,8 @@ class Import < ActiveRecord::Base
has_many :resources, class_name: "ImportResource", dependent: :destroy
has_many :children, foreign_key: :parent_id, class_name: "Import", dependent: :destroy
- scope :where_started_at_between, ->(start_date, end_date) do
- where('started_at BETWEEN ? AND ?', start_date, end_date)
+ scope :where_started_at_in, ->(period_range) do
+ where('started_at BETWEEN :begin AND :end', begin: period_range.begin, end: period_range.end)
end
extend Enumerize
diff --git a/app/models/journey_pattern_control/duplicates.rb b/app/models/journey_pattern_control/duplicates.rb
index 78ca07e90..e06e6021b 100644
--- a/app/models/journey_pattern_control/duplicates.rb
+++ b/app/models/journey_pattern_control/duplicates.rb
@@ -1,13 +1,6 @@
module JourneyPatternControl
class Duplicates < ComplianceControl
- @@default_criticity = :warning
- @@default_code = "3-JourneyPattern-1"
-
- after_initialize do
- self.name = self.class.name
- self.code = @@default_code
- self.criticity = @@default_criticity
- end
+ def self.default_code; "3-JourneyPattern-1" end
end
end
diff --git a/app/models/journey_pattern_control/vehicle_journey.rb b/app/models/journey_pattern_control/vehicle_journey.rb
index a90c16138..dfaf42beb 100644
--- a/app/models/journey_pattern_control/vehicle_journey.rb
+++ b/app/models/journey_pattern_control/vehicle_journey.rb
@@ -1,13 +1,6 @@
module JourneyPatternControl
class VehicleJourney < ComplianceControl
- @@default_criticity = :warning
- @@default_code = "3-JourneyPattern-2"
-
- after_initialize do
- self.name = self.class.name
- self.code = @@default_code
- self.criticity = @@default_criticity
- end
+ def self.default_code; "3-JourneyPattern-2" end
end
-end \ No newline at end of file
+end
diff --git a/app/models/line_control/route.rb b/app/models/line_control/route.rb
index 8ac13a080..aabd2f347 100644
--- a/app/models/line_control/route.rb
+++ b/app/models/line_control/route.rb
@@ -1,13 +1,6 @@
module LineControl
class Route < ComplianceControl
- @@default_criticity = :warning
- @@default_code = "3-Line-1"
-
- after_initialize do
- self.name = self.class.name
- self.code = @@default_code
- self.criticity = @@default_criticity
- end
+ def self.default_code; "3-Line-1" end
end
-end \ No newline at end of file
+end
diff --git a/app/models/line_referential.rb b/app/models/line_referential.rb
index 8bbc32993..8bc6adec3 100644
--- a/app/models/line_referential.rb
+++ b/app/models/line_referential.rb
@@ -1,4 +1,6 @@
class LineReferential < ActiveRecord::Base
+ extend StifTransportModeEnumerations
+
has_many :line_referential_memberships
has_many :organisations, through: :line_referential_memberships
has_many :lines, class_name: 'Chouette::Line'
@@ -25,8 +27,4 @@ class LineReferential < ActiveRecord::Base
def last_sync
line_referential_syncs.last
end
-
- def transport_modes
- Chouette::TransportMode.all.select { |tm| tm.to_i > 0 }
- end
end
diff --git a/app/models/organisation.rb b/app/models/organisation.rb
index ba65ad375..6104b4431 100644
--- a/app/models/organisation.rb
+++ b/app/models/organisation.rb
@@ -3,7 +3,7 @@ class Organisation < ActiveRecord::Base
has_many :users, :dependent => :destroy
has_many :referentials, :dependent => :destroy
- has_many :rule_parameter_sets, :dependent => :destroy
+ # has_many :rule_parameter_sets, :dependent => :destroy
has_many :compliance_control_sets, :dependent => :destroy
has_many :stop_area_referential_memberships
@@ -19,11 +19,11 @@ class Organisation < ActiveRecord::Base
validates_presence_of :name
validates_uniqueness_of :code
- after_create :add_rule_parameter_set
+ # after_create :add_rule_parameter_set
- def add_rule_parameter_set
- RuleParameterSet.default_for_all_modes( self).save
- end
+ # def add_rule_parameter_set
+ # RuleParameterSet.default_for_all_modes( self).save
+ # end
def self.portail_api_request
conf = Rails.application.config.try(:stif_portail_api)
diff --git a/app/models/route_control/duplicates.rb b/app/models/route_control/duplicates.rb
index 379d7cf98..99e3b3aa8 100644
--- a/app/models/route_control/duplicates.rb
+++ b/app/models/route_control/duplicates.rb
@@ -1,13 +1,6 @@
module RouteControl
class Duplicates < ComplianceControl
- @@default_criticity = :warning
- @@default_code = "3-Route-4"
-
- after_initialize do
- self.name = self.class.name
- self.code = @@default_code
- self.criticity = @@default_criticity
- end
+ def self.default_code; "3-Route-4" end
end
end
diff --git a/app/models/route_control/journey_pattern.rb b/app/models/route_control/journey_pattern.rb
index 0559fac42..63cec2a41 100644
--- a/app/models/route_control/journey_pattern.rb
+++ b/app/models/route_control/journey_pattern.rb
@@ -1,13 +1,6 @@
module RouteControl
class JourneyPattern < ComplianceControl
- @@default_criticity = :warning
- @@default_code = "3-Route-3"
-
- after_initialize do
- self.name = self.class.name
- self.code = @@default_code
- self.criticity = @@default_criticity
- end
+ def self.default_code; "3-Route-3" end
end
-end \ No newline at end of file
+end
diff --git a/app/models/route_control/minimum_length.rb b/app/models/route_control/minimum_length.rb
index 14bc7064f..56becfb2b 100644
--- a/app/models/route_control/minimum_length.rb
+++ b/app/models/route_control/minimum_length.rb
@@ -1,13 +1,6 @@
module RouteControl
class MinimumLength < ComplianceControl
- @@default_criticity = :error
- @@default_code = "3-Route-6"
-
- after_initialize do
- self.name = self.class.name
- self.code = @@default_code
- self.criticity = @@default_criticity
- end
+ def self.default_code; "3-Route-6" end
end
end
diff --git a/app/models/route_control/omnibus_journey_pattern.rb b/app/models/route_control/omnibus_journey_pattern.rb
index 2f09ff735..af3004ad7 100644
--- a/app/models/route_control/omnibus_journey_pattern.rb
+++ b/app/models/route_control/omnibus_journey_pattern.rb
@@ -1,13 +1,6 @@
module RouteControl
class OmnibusJourneyPattern < ComplianceControl
- @@default_criticity = :warning
- @@default_code = "3-Route-9"
-
- after_initialize do
- self.name = self.class.name
- self.code = @@default_code
- self.criticity = @@default_criticity
- end
+ def self.default_code; "3-Route-9" end
end
end
diff --git a/app/models/route_control/opposite_route.rb b/app/models/route_control/opposite_route.rb
index d5f2bc59e..0148087ca 100644
--- a/app/models/route_control/opposite_route.rb
+++ b/app/models/route_control/opposite_route.rb
@@ -1,14 +1,6 @@
module RouteControl
class OppositeRoute < ComplianceControl
- @@default_criticity = :error
- @@default_code = "3-Route-2"
-
- after_initialize do
- self.name = self.class.name
- self.code = @@default_code
- self.criticity = @@default_criticity
- end
-
+ def self.default_code; "3-Route-2" end
end
end
diff --git a/app/models/route_control/opposite_route_terminus.rb b/app/models/route_control/opposite_route_terminus.rb
index e72229ca3..e12690d48 100644
--- a/app/models/route_control/opposite_route_terminus.rb
+++ b/app/models/route_control/opposite_route_terminus.rb
@@ -1,13 +1,6 @@
module RouteControl
class OppositeRouteTerminus < ComplianceControl
- @@default_criticity = :warning
- @@default_code = "3-Route-5"
-
- after_initialize do
- self.name = self.class.name
- self.code = @@default_code
- self.criticity = @@default_criticity
- end
+ def self.default_code; "3-Route-5" end
end
-end \ No newline at end of file
+end
diff --git a/app/models/route_control/speed.rb b/app/models/route_control/speed.rb
deleted file mode 100644
index fb07b5c87..000000000
--- a/app/models/route_control/speed.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-module VehicleJourneyControl
- class Speed < ComplianceControl
-
- hstore_accessor :control_attributes, minimum: :integer, maximum: :integer
-
- @@default_criticity = :warning
- @@default_code = "3-VehicleJourney-2"
-
- after_initialize do
- self.name = self.class.name
- self.code = @@default_code
- self.criticity = @@default_criticity
- end
- end
-end
diff --git a/app/models/route_control/stop_points_in_journey_pattern.rb b/app/models/route_control/stop_points_in_journey_pattern.rb
index 195257a4a..c0c13e65a 100644
--- a/app/models/route_control/stop_points_in_journey_pattern.rb
+++ b/app/models/route_control/stop_points_in_journey_pattern.rb
@@ -1,13 +1,6 @@
module RouteControl
- class StopPointInJourneyPattern < ComplianceControl
+ class StopPointsInJourneyPattern < ComplianceControl
- @@default_criticity = :error
- @@default_code = "3-Route-6"
-
- after_initialize do
- self.name = self.class.name
- self.code = @@default_code
- self.criticity = @@default_criticity
- end
+ def self.default_code; "3-Route-8" end
end
end
diff --git a/app/models/route_control/time_table.rb b/app/models/route_control/time_table.rb
deleted file mode 100644
index 911807ba9..000000000
--- a/app/models/route_control/time_table.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-module VehicleJourneyControl
- class TimeTable < ComplianceControl
-
- @@default_criticity = :error
- @@default_code = "3-VehicleJourney-4"
-
- after_initialize do
- self.name = self.class.name
- self.code = @@default_code
- self.criticity = @@default_criticity
- end
- end
-end
diff --git a/app/models/route_control/unactivated_stop_points.rb b/app/models/route_control/unactivated_stop_points.rb
index 8ab680490..a903fff53 100644
--- a/app/models/route_control/unactivated_stop_points.rb
+++ b/app/models/route_control/unactivated_stop_points.rb
@@ -1,13 +1,6 @@
module RouteControl
- class UnactivatedStopPoint < ComplianceControl
+ class UnactivatedStopPoints < ComplianceControl
- @@default_criticity = :warning
- @@default_code = "3-Route-10"
-
- after_initialize do
- self.name = self.class.name
- self.code = @@default_code
- self.criticity = @@default_criticity
- end
+ def self.default_code; "3-Route-10" end
end
end
diff --git a/app/models/route_control/vehicle_journey_at_stops.rb b/app/models/route_control/vehicle_journey_at_stops.rb
deleted file mode 100644
index 02a43fb10..000000000
--- a/app/models/route_control/vehicle_journey_at_stops.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-module VehicleJourneyControl
- class VehicleJourneyAtStops < ComplianceControl
-
- @@default_criticity = :error
- @@default_code = "3-VehicleJourney-5"
-
- after_initialize do
- self.name = self.class.name
- self.code = @@default_code
- self.criticity = @@default_criticity
- end
- end
-end
diff --git a/app/models/route_control/zdl_stop_area.rb b/app/models/route_control/zdl_stop_area.rb
index 4561c9b2e..2efd892df 100644
--- a/app/models/route_control/zdl_stop_area.rb
+++ b/app/models/route_control/zdl_stop_area.rb
@@ -1,13 +1,6 @@
module RouteControl
class ZDLStopArea < ComplianceControl
- @@default_criticity = :warning
- @@default_code = "3-Route-1"
-
- after_initialize do
- self.name = self.class.name
- self.code = @@default_code
- self.criticity = @@default_criticity
- end
+ def self.default_code; "3-Route-1" end
end
end
diff --git a/app/models/routing_constaint_zone_control/maximum_length.rb b/app/models/routing_constaint_zone_control/maximum_length.rb
deleted file mode 100644
index fd63ffeda..000000000
--- a/app/models/routing_constaint_zone_control/maximum_length.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-module RoutingConstaintZoneControl
- class MaximumLength < ComplianceControl
-
- @@default_criticity = :warning
- @@default_code = "3-ITL-2"
-
- after_initialize do
- self.name = self.class.name
- self.code = @@default_code
- self.criticity = @@default_criticity
- end
- end
-end \ No newline at end of file
diff --git a/app/models/routing_constaint_zone_control/minimum_length.rb b/app/models/routing_constaint_zone_control/minimum_length.rb
deleted file mode 100644
index c17bbc834..000000000
--- a/app/models/routing_constaint_zone_control/minimum_length.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-module RoutingConstaintZoneControl
- class MinimumLength < ComplianceControl
-
- @@default_criticity = :warning
- @@default_code = "3-ITL-3"
-
- after_initialize do
- self.name = self.class.name
- self.code = @@default_code
- self.criticity = @@default_criticity
- end
- end
-end \ No newline at end of file
diff --git a/app/models/routing_constaint_zone_control/unactivated_stop_point.rb b/app/models/routing_constaint_zone_control/unactivated_stop_point.rb
deleted file mode 100644
index 92a1d1a58..000000000
--- a/app/models/routing_constaint_zone_control/unactivated_stop_point.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-module RoutingConstaintZoneControl
- class UnactivatedStopPoint < ComplianceControl
-
- @@default_criticity = :warning
- @@default_code = "3-ITL-1"
-
- after_initialize do
- self.name = self.class.name
- self.code = @@default_code
- self.criticity = @@default_criticity
- end
- end
-end
diff --git a/app/models/routing_constraint_zone_control/maximum_length.rb b/app/models/routing_constraint_zone_control/maximum_length.rb
new file mode 100644
index 000000000..6b726e38c
--- /dev/null
+++ b/app/models/routing_constraint_zone_control/maximum_length.rb
@@ -0,0 +1,6 @@
+module RoutingConstraintZoneControl
+ class MaximumLength < ComplianceControl
+
+ def self.default_code; "3-ITL-2" end
+ end
+end
diff --git a/app/models/routing_constraint_zone_control/minimum_length.rb b/app/models/routing_constraint_zone_control/minimum_length.rb
new file mode 100644
index 000000000..38f583bc5
--- /dev/null
+++ b/app/models/routing_constraint_zone_control/minimum_length.rb
@@ -0,0 +1,6 @@
+module RoutingConstraintZoneControl
+ class MinimumLength < ComplianceControl
+
+ def self.default_code; "3-ITL-3" end
+ end
+end
diff --git a/app/models/routing_constraint_zone_control/unactivated_stop_point.rb b/app/models/routing_constraint_zone_control/unactivated_stop_point.rb
new file mode 100644
index 000000000..c03bb2324
--- /dev/null
+++ b/app/models/routing_constraint_zone_control/unactivated_stop_point.rb
@@ -0,0 +1,6 @@
+module RoutingConstraintZoneControl
+ class UnactivatedStopPoint < ComplianceControl
+
+ def self.default_code; "3-ITL-1" end
+ end
+end
diff --git a/app/models/rule_parameter_set.rb b/app/models/rule_parameter_set.rb
index db78a2f8a..91e575822 100644
--- a/app/models/rule_parameter_set.rb
+++ b/app/models/rule_parameter_set.rb
@@ -65,7 +65,26 @@ class RuleParameterSet < ActiveRecord::Base
end
def self.all_modes
- Chouette::TransportMode.all.map { |m| m.to_s}
+ ["interchange",
+ "unknown",
+ "coach",
+ "air",
+ "waterborne",
+ "bus",
+ "ferry",
+ "walk",
+ "metro",
+ "shuttle",
+ "rapid_transit",
+ "taxi",
+ "local_train",
+ "train",
+ "long_distance_train",
+ "tramway",
+ "trolleybus",
+ "private_vehicle",
+ "bicycle",
+ "other"]
end
def self.mode_attribute?( method_name )
diff --git a/app/models/stif_transport_mode_enumerations.rb b/app/models/stif_transport_mode_enumerations.rb
deleted file mode 100644
index a9a3fc3e0..000000000
--- a/app/models/stif_transport_mode_enumerations.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-module StifTransportModeEnumerations
- extend Enumerize
-
- enumerize :transport_mode, in: %w(air bus coach ferry metro rail trolleyBus tram water cableway funicular other)
-end
diff --git a/app/models/vechicle_journey_control/delta.rb b/app/models/vechicle_journey_control/delta.rb
deleted file mode 100644
index d4e1e6eca..000000000
--- a/app/models/vechicle_journey_control/delta.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-module VehicleJourneyControl
- class Delta < ComplianceControl
-
- hstore_accessor :control_attributes, delta: :integer
-
- @@default_criticity = :warning
- @@default_code = "3-VehicleJourney-3"
-
- after_initialize do
- self.name = self.class.name
- self.code = @@default_code
- self.criticity = @@default_criticity
- end
- end
-end
diff --git a/app/models/vechicle_journey_control/waiting_time.rb b/app/models/vechicle_journey_control/waiting_time.rb
deleted file mode 100644
index a7e90b6ac..000000000
--- a/app/models/vechicle_journey_control/waiting_time.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-module VehicleJourneyControl
- class WatingTime < ComplianceControl
-
- @@default_criticity = :warning
- @@default_code = "3-VehicleJourney-1"
-
- after_initialize do
- self.name = self.class.name
- self.code = @@default_code
- self.criticity = @@default_criticity
- end
- end
-end
diff --git a/app/models/vehicle_journey_control/delta.rb b/app/models/vehicle_journey_control/delta.rb
new file mode 100644
index 000000000..1f3a4d492
--- /dev/null
+++ b/app/models/vehicle_journey_control/delta.rb
@@ -0,0 +1,10 @@
+module VehicleJourneyControl
+ class Delta < ComplianceControl
+
+ hstore_accessor :control_attributes, maximum: :integer
+
+ validates :maximum, numericality: true, allow_nil: true
+
+ def self.default_code; "3-VehicleJourney-3" end
+ end
+end
diff --git a/app/models/vehicle_journey_control/speed.rb b/app/models/vehicle_journey_control/speed.rb
new file mode 100644
index 000000000..be9f838e4
--- /dev/null
+++ b/app/models/vehicle_journey_control/speed.rb
@@ -0,0 +1,11 @@
+module VehicleJourneyControl
+ class Speed < ComplianceControl
+ hstore_accessor :control_attributes, minimum: :integer, maximum: :integer
+
+ validates :minimum, numericality: true, allow_nil: true
+ validates :maximum, numericality: true, allow_nil: true
+ include MinMaxValuesValidation
+
+ def self.default_code; "3-VehicleJourney-2" end
+ end
+end
diff --git a/app/models/vehicle_journey_control/time_table.rb b/app/models/vehicle_journey_control/time_table.rb
new file mode 100644
index 000000000..617ead12b
--- /dev/null
+++ b/app/models/vehicle_journey_control/time_table.rb
@@ -0,0 +1,6 @@
+module VehicleJourneyControl
+ class TimeTable < ComplianceControl
+
+ def self.default_code; "3-VehicleJourney-4" end
+ end
+end
diff --git a/app/models/vehicle_journey_control/vehicle_journey_at_stops.rb b/app/models/vehicle_journey_control/vehicle_journey_at_stops.rb
new file mode 100644
index 000000000..47ee26f82
--- /dev/null
+++ b/app/models/vehicle_journey_control/vehicle_journey_at_stops.rb
@@ -0,0 +1,6 @@
+module VehicleJourneyControl
+ class VehicleJourneyAtStops < ComplianceControl
+
+ def self.default_code; "3-VehicleJourney-5" end
+ end
+end
diff --git a/app/models/vehicle_journey_control/waiting_time.rb b/app/models/vehicle_journey_control/waiting_time.rb
new file mode 100644
index 000000000..68fccb5c1
--- /dev/null
+++ b/app/models/vehicle_journey_control/waiting_time.rb
@@ -0,0 +1,9 @@
+module VehicleJourneyControl
+ class WaitingTime < ComplianceControl
+ hstore_accessor :control_attributes, maximum: :integer
+
+ validates :maximum, numericality: true, allow_nil: true
+
+ def self.default_code; "3-VehicleJourney-1" end
+ end
+end
diff --git a/app/models/vehicle_journey_import.rb b/app/models/vehicle_journey_import.rb
index 44a6d457e..250f3a9e9 100644
--- a/app/models/vehicle_journey_import.rb
+++ b/app/models/vehicle_journey_import.rb
@@ -1,5 +1,3 @@
-# -*- coding: utf-8 -*-
-
class VehicleJourneyImport
include ActiveModel::Validations
include ActiveModel::Conversion
diff --git a/app/models/workbench.rb b/app/models/workbench.rb
index 30692e625..c304e8ba9 100644
--- a/app/models/workbench.rb
+++ b/app/models/workbench.rb
@@ -2,6 +2,7 @@ class Workbench < ActiveRecord::Base
belongs_to :organisation
belongs_to :line_referential
belongs_to :stop_area_referential
+ belongs_to :output, class_name: 'ReferentialSuite'
has_many :lines, -> (workbench) { Stif::MyWorkbenchScopes.new(workbench).line_scope(self) }, through: :line_referential
has_many :networks, through: :line_referential
@@ -10,13 +11,18 @@ class Workbench < ActiveRecord::Base
has_many :stop_areas, through: :stop_area_referential
has_many :imports
has_many :workbench_imports
+ has_many :compliance_check_sets
+ has_many :compliance_control_sets
validates :name, presence: true
validates :organisation, presence: true
+ validates :output, presence: true
has_many :referentials
has_many :referential_metadatas, through: :referentials, source: :metadatas
+ before_validation :initialize_output
+
def all_referentials
if line_ids.empty?
@@ -26,4 +32,12 @@ class Workbench < ActiveRecord::Base
end
end
+ private
+
+ def initialize_output
+ # Don't reset `output` if it's already initialised
+ return if !output.nil?
+
+ self.output = ReferentialSuite.create
+ end
end