aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZakaria BOUZIANE2015-03-09 14:01:10 +0100
committerZakaria BOUZIANE2015-03-09 14:01:10 +0100
commit0d5adf2fad5c0ddd8efc1eca9dc6d8e9c48b049d (patch)
tree36e3d37edd325d59b6056c738305d5d60f74beee
parentf0456f7334b8fb4442a51bb370fdc0c5a3ea2cd0 (diff)
downloadchouette-core-0d5adf2fad5c0ddd8efc1eca9dc6d8e9c48b049d.tar.bz2
Prepare merging V2_5 into V3
-rw-r--r--app/models/data_format_enumerations.rb6
-rw-r--r--app/models/organisation.rb11
-rw-r--r--app/models/referential.rb4
-rw-r--r--app/models/rule_parameter_set.rb15
-rw-r--r--app/models/stop_area_copy.rb49
-rw-r--r--app/models/vehicle_identifier.rb16
-rw-r--r--db/migrate/20131104110509_create_rule_parameter_sets.rb2
-rw-r--r--db/migrate/20150120125337_create_footnotes.ninoxe_engine.rb12
-rw-r--r--db/migrate/20150120183020_create_vehicle_journey_footnotes.ninoxe_engine.rb9
-rw-r--r--db/migrate/20150121144108_add_hub_restrictions_to_organisation.rb10
-rw-r--r--db/migrate/20150129170104_add_organisation_id_rule_parameter_set.rb9
-rw-r--r--db/migrate/20150218175300_set_organisation_id_to_rps.rb19
-rw-r--r--db/migrate/20150219175300_insert_default_organisation.rb21
-rw-r--r--db/migrate/20150219205300_remove_referential_id_to_rule_parameter_set.rb9
-rw-r--r--db/migrate/20150304084602_remove_hub_restrictions_from_referentials.rb5
-rw-r--r--db/migrate/20150304084646_remove_hub_restrictions_by_default_from_organisations.rb5
-rw-r--r--db/migrate/20150304090707_add_data_format_to_referentials.rb5
-rw-r--r--db/migrate/20150304090743_add_data_format_to_organisations.rb5
-rw-r--r--db/schema.rb27
19 files changed, 210 insertions, 29 deletions
diff --git a/app/models/data_format_enumerations.rb b/app/models/data_format_enumerations.rb
new file mode 100644
index 000000000..2e5586403
--- /dev/null
+++ b/app/models/data_format_enumerations.rb
@@ -0,0 +1,6 @@
+module DataFormatEnumerations
+ extend Enumerize
+ extend ActiveModel::Naming
+
+ enumerize :data_format, in: %w[neptune netex gtfs hub]
+end
diff --git a/app/models/organisation.rb b/app/models/organisation.rb
index f4b2e35f8..8fafa56a0 100644
--- a/app/models/organisation.rb
+++ b/app/models/organisation.rb
@@ -1,7 +1,18 @@
# -*- coding: utf-8 -*-
class Organisation < ActiveRecord::Base
+ include DataFormatEnumerations
+
has_many :users, :dependent => :destroy
has_many :referentials, :dependent => :destroy
+ has_many :rule_parameter_sets, :dependent => :destroy
validates :name, :presence => true, :uniqueness => true
+
+ after_create :add_rule_parameter_set
+
+ #attr_accessible :data_format, :name
+
+ def add_rule_parameter_set
+ RuleParameterSet.default_for_all_modes( self).save
+ end
end
diff --git a/app/models/referential.rb b/app/models/referential.rb
index be6e3a3ad..97331c1c3 100644
--- a/app/models/referential.rb
+++ b/app/models/referential.rb
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
class Referential < ActiveRecord::Base
+ include DataFormatEnumerations
+
validates_presence_of :name
validates_presence_of :slug
validates_presence_of :prefix
@@ -18,7 +20,7 @@ class Referential < ActiveRecord::Base
attr_accessor :lower_corner
has_one :user
- has_many :rule_parameter_sets, :dependent => :destroy
+ ##has_many :rule_parameter_sets, :dependent => :destroy
has_many :import_tasks, :dependent => :destroy
has_many :compliance_check_tasks, :dependent => :destroy
has_many :exports, :dependent => :destroy
diff --git a/app/models/rule_parameter_set.rb b/app/models/rule_parameter_set.rb
index 227e2cddf..3c0d687b1 100644
--- a/app/models/rule_parameter_set.rb
+++ b/app/models/rule_parameter_set.rb
@@ -1,12 +1,12 @@
class RuleParameterSet < ActiveRecord::Base
- belongs_to :referential
+ belongs_to :organisation
- validates_presence_of :referential
+ #validates_presence_of :referential
validates_presence_of :name
serialize :parameters, JSON
- #attr_accessible :name, :referential_id
+ #attr_accessible :name, :organisation_id
def self.mode_attribute_prefixes
%w( allowed_transport inter_stop_area_distance_min inter_stop_area_distance_max speed_max speed_min inter_stop_duration_variation_max)
@@ -307,16 +307,15 @@ class RuleParameterSet < ActiveRecord::Base
}
# :waterborne, :bus, :ferry, :walk, :metro, :shuttle, :rapidtransit, :taxi, :localtrain, :train, :longdistancetrain, :tramway, :trolleybus, :privatevehicle, :bicycle, :other
end
- def self.default( referential)
- self.default_for_all_modes( referential).tap do |rps|
+ def self.default( organisation)
+ self.default_for_all_modes( organisation).tap do |rps|
rps.name = ""
end
end
- def self.default_for_all_modes( referential)
+ def self.default_for_all_modes( organisation)
mode_attributes = mode_default_params.values.inject(self.default_params){|memo, obj| memo.merge! obj}
self.new(
- { :referential_id => referential.id,
- :stop_areas_area => referential.envelope.to_polygon.points.map(&:to_coordinates).to_json,
+ { :organisation_id => organisation.id,
:name => "valeurs par defaut"
}.merge( mode_attributes))
end
diff --git a/app/models/stop_area_copy.rb b/app/models/stop_area_copy.rb
index 041d30eb9..928b66a52 100644
--- a/app/models/stop_area_copy.rb
+++ b/app/models/stop_area_copy.rb
@@ -36,33 +36,56 @@ class StopAreaCopy
false
end
+ def source
+ @source ||= Chouette::StopArea.find self.source_id
+ end
+
+ def copy
+ @copy ||= self.source.duplicate
+ end
+
+ def copy_is_source_parent?
+ self.hierarchy == "parent"
+ end
+
+ def copy_is_source_child?
+ self.hierarchy == "child"
+ end
+
+ def copy_modfied_attributes
+ { :name => self.source.name, # TODO: change ninoxe to avoid that !!!
+ :area_type => self.area_type.camelcase,
+ :registration_number => nil,
+ :parent_id => copy_is_source_child? ? self.source_id : self.copy.parent_id
+ }
+ end
+
+ def source_modified_attributes
+ return {} unless copy_is_source_parent?
+ { :parent_id => self.copy.id
+ }
+ end
+
def save
begin
if self.valid?
- self.source ||= Chouette::StopArea.find self.source_id
- self.copy = source.duplicate
- self.copy.name = source.name
- self.copy.area_type = self.area_type.camelcase
Chouette::StopArea.transaction do
- if self.hierarchy == "child"
- self.copy.parent_id = source.id
- end
- self.copy.save!
- if self.hierarchy == "parent"
- self.source.parent_id = copy.id
- self.source.save!
+ copy.update_attributes copy_modfied_attributes
+ unless source_modified_attributes.empty?
+ source.update_attributes source_modified_attributes
end
end
true
else
- false
+ false
end
rescue Exception => exception
Rails.logger.error(exception.message)
+ Rails.logger.error(exception.backtrace.join("\n"))
errors.add :base, I18n.t("stop_area_copies.errors.exception")
false
end
- end
+ end
end
diff --git a/app/models/vehicle_identifier.rb b/app/models/vehicle_identifier.rb
new file mode 100644
index 000000000..f53725c74
--- /dev/null
+++ b/app/models/vehicle_identifier.rb
@@ -0,0 +1,16 @@
+class VehicleIdentifier
+
+ def self.auto_identify_vehicles
+
+ #max_identifier = Chouette::VehicleJourney.
+ Chouette::VehicleJourney.transaction do
+ vehicles = Chouette::VehicleJourney.lock(true).all
+ max = vehicles.map(&:vehicle_type_identifier).compact.map(&:to_i).max
+
+ vehicles.select {|v| v.vehicle_type_identifier.nil? }.each_with_index do |v, index|
+ v.update_attributes :vehicle_type_identifier => ( max.to_i + index + 1)
+ end
+ end
+ end
+
+end
diff --git a/db/migrate/20131104110509_create_rule_parameter_sets.rb b/db/migrate/20131104110509_create_rule_parameter_sets.rb
index b2ceb0dbb..01ddef4a7 100644
--- a/db/migrate/20131104110509_create_rule_parameter_sets.rb
+++ b/db/migrate/20131104110509_create_rule_parameter_sets.rb
@@ -2,7 +2,7 @@ class CreateRuleParameterSets < ActiveRecord::Migration
def up
unless table_exists? :rule_parameter_sets
create_table :rule_parameter_sets do |a|
- a.belongs_to :referential ,:limit => 8
+ a.integer :referential_id ,:limit => 8
a.text :parameters
a.string :name
a.timestamps
diff --git a/db/migrate/20150120125337_create_footnotes.ninoxe_engine.rb b/db/migrate/20150120125337_create_footnotes.ninoxe_engine.rb
new file mode 100644
index 000000000..ce27d4ee8
--- /dev/null
+++ b/db/migrate/20150120125337_create_footnotes.ninoxe_engine.rb
@@ -0,0 +1,12 @@
+# This migration comes from ninoxe_engine (originally 20150115153453)
+class CreateFootnotes < ActiveRecord::Migration
+ def change
+ create_table :footnotes do |t|
+ t.integer "line_id", :limit => 8
+ t.string :code
+ t.string :label
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20150120183020_create_vehicle_journey_footnotes.ninoxe_engine.rb b/db/migrate/20150120183020_create_vehicle_journey_footnotes.ninoxe_engine.rb
new file mode 100644
index 000000000..220d69d01
--- /dev/null
+++ b/db/migrate/20150120183020_create_vehicle_journey_footnotes.ninoxe_engine.rb
@@ -0,0 +1,9 @@
+# This migration comes from ninoxe_engine (originally 20150119160029)
+class CreateVehicleJourneyFootnotes < ActiveRecord::Migration
+ def change
+ create_table :footnotes_vehicle_journeys, :id => false, :force => true do |t|
+ t.integer "vehicle_journey_id", :limit => 8
+ t.integer "footnote_id", :limit => 8
+ end
+ end
+end
diff --git a/db/migrate/20150121144108_add_hub_restrictions_to_organisation.rb b/db/migrate/20150121144108_add_hub_restrictions_to_organisation.rb
new file mode 100644
index 000000000..27955b43f
--- /dev/null
+++ b/db/migrate/20150121144108_add_hub_restrictions_to_organisation.rb
@@ -0,0 +1,10 @@
+class AddHubRestrictionsToOrganisation < ActiveRecord::Migration
+ def self.up
+ add_column :organisations, :hub_restrictions_by_default, :boolean
+ add_column :referentials, :hub_restrictions, :boolean
+ end
+ def self.down
+ remove_column :organisations, :hub_restrictions_by_default
+ remove_column :referentials, :hub_restrictions
+ end
+end
diff --git a/db/migrate/20150129170104_add_organisation_id_rule_parameter_set.rb b/db/migrate/20150129170104_add_organisation_id_rule_parameter_set.rb
new file mode 100644
index 000000000..8b3f52caf
--- /dev/null
+++ b/db/migrate/20150129170104_add_organisation_id_rule_parameter_set.rb
@@ -0,0 +1,9 @@
+class AddOrganisationIdRuleParameterSet < ActiveRecord::Migration
+ def up
+ add_column :rule_parameter_sets, :organisation_id, :integer, :limit => 8
+ end
+
+ def down
+ remove_column :rule_parameter_sets, :organisation_id
+ end
+end
diff --git a/db/migrate/20150218175300_set_organisation_id_to_rps.rb b/db/migrate/20150218175300_set_organisation_id_to_rps.rb
new file mode 100644
index 000000000..f7028449d
--- /dev/null
+++ b/db/migrate/20150218175300_set_organisation_id_to_rps.rb
@@ -0,0 +1,19 @@
+class SetOrganisationIdToRps < ActiveRecord::Migration
+ #class RuleParameterSet < ActiveRecord::Base
+ #attr_accessor :referential_id
+ #attr_accessor :organisation_id
+ #attr_accessor :name
+ #end
+ #def up
+ #RuleParameterSet.all.each_with_index do |rps, index|
+ # rps.update_attributes :organisation_id => Referential.find( rps.referential_id).organisation_id,
+ # :name => "#{rps.name} #{index}"
+ #end
+ #end
+
+ #def down
+ #RuleParameterSet.all.each_with_index do |rps, index|
+ # rps.update_attributes :organisation_id => nil
+ #end
+ #end
+end
diff --git a/db/migrate/20150219175300_insert_default_organisation.rb b/db/migrate/20150219175300_insert_default_organisation.rb
new file mode 100644
index 000000000..d151c3800
--- /dev/null
+++ b/db/migrate/20150219175300_insert_default_organisation.rb
@@ -0,0 +1,21 @@
+class InsertDefaultOrganisation < ActiveRecord::Migration
+ # def up
+ # organisation = Organisation.find_or_create_by(:name => "Chouette")
+ # Referential.where( :organisation_id => nil).each do |r|
+ # r.update_attributes :organisation_id => organisation.id
+ # end
+ # User.where( :organisation_id => nil).each do |r|
+ # r.update_attributes :organisation_id => organisation.id
+ # end
+ # Organisation.all.each do |organisation|
+ # RuleParameterSet.default_for_all_modes( organisation).save if organisation.rule_parameter_sets.empty?
+ # end
+
+ # end
+
+ # def down
+ # organisations = Organisation.where( :name => "Chouette")
+ # organisations.first.destroy unless organisations.empty?
+ # end
+end
+
diff --git a/db/migrate/20150219205300_remove_referential_id_to_rule_parameter_set.rb b/db/migrate/20150219205300_remove_referential_id_to_rule_parameter_set.rb
new file mode 100644
index 000000000..747557ef0
--- /dev/null
+++ b/db/migrate/20150219205300_remove_referential_id_to_rule_parameter_set.rb
@@ -0,0 +1,9 @@
+class RemoveReferentialIdToRuleParameterSet < ActiveRecord::Migration
+ def up
+ remove_column :rule_parameter_sets, :referential_id
+ end
+ def down
+ add_column :rule_parameter_sets, :referential_id, :int
+ end
+end
+
diff --git a/db/migrate/20150304084602_remove_hub_restrictions_from_referentials.rb b/db/migrate/20150304084602_remove_hub_restrictions_from_referentials.rb
new file mode 100644
index 000000000..354203603
--- /dev/null
+++ b/db/migrate/20150304084602_remove_hub_restrictions_from_referentials.rb
@@ -0,0 +1,5 @@
+class RemoveHubRestrictionsFromReferentials < ActiveRecord::Migration
+ def change
+ remove_column :referentials, :hub_restrictions
+ end
+end
diff --git a/db/migrate/20150304084646_remove_hub_restrictions_by_default_from_organisations.rb b/db/migrate/20150304084646_remove_hub_restrictions_by_default_from_organisations.rb
new file mode 100644
index 000000000..daa79707b
--- /dev/null
+++ b/db/migrate/20150304084646_remove_hub_restrictions_by_default_from_organisations.rb
@@ -0,0 +1,5 @@
+class RemoveHubRestrictionsByDefaultFromOrganisations < ActiveRecord::Migration
+ def change
+ remove_column :organisations, :hub_restrictions_by_default
+ end
+end
diff --git a/db/migrate/20150304090707_add_data_format_to_referentials.rb b/db/migrate/20150304090707_add_data_format_to_referentials.rb
new file mode 100644
index 000000000..5d5df65d5
--- /dev/null
+++ b/db/migrate/20150304090707_add_data_format_to_referentials.rb
@@ -0,0 +1,5 @@
+class AddDataFormatToReferentials < ActiveRecord::Migration
+ def change
+ add_column :referentials, :data_format, :string
+ end
+end
diff --git a/db/migrate/20150304090743_add_data_format_to_organisations.rb b/db/migrate/20150304090743_add_data_format_to_organisations.rb
new file mode 100644
index 000000000..2222c0b08
--- /dev/null
+++ b/db/migrate/20150304090743_add_data_format_to_organisations.rb
@@ -0,0 +1,5 @@
+class AddDataFormatToOrganisations < ActiveRecord::Migration
+ def change
+ add_column :organisations, :data_format, :string
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 5714242ae..b7feb13be 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20150226083920) do
+ActiveRecord::Schema.define(version: 20150304090743) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -195,6 +195,19 @@ ActiveRecord::Schema.define(version: 20150226083920) do
t.integer "choice_code"
end
+ create_table "footnotes", force: true do |t|
+ t.integer "line_id", limit: 8
+ t.string "code"
+ t.string "label"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ create_table "footnotes_vehicle_journeys", id: false, force: true do |t|
+ t.integer "vehicle_journey_id", limit: 8
+ t.integer "footnote_id", limit: 8
+ end
+
create_table "group_of_lines", force: true do |t|
t.string "objectid", null: false
t.integer "object_version"
@@ -310,8 +323,9 @@ ActiveRecord::Schema.define(version: 20150226083920) do
create_table "organisations", force: true do |t|
t.string "name"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.string "data_format"
end
create_table "pt_links", force: true do |t|
@@ -342,6 +356,7 @@ ActiveRecord::Schema.define(version: 20150226083920) do
t.text "geographical_bounds"
t.integer "user_id", limit: 8
t.string "user_name"
+ t.string "data_format"
end
create_table "routes", force: true do |t|
@@ -367,11 +382,11 @@ ActiveRecord::Schema.define(version: 20150226083920) do
end
create_table "rule_parameter_sets", force: true do |t|
- t.integer "referential_id", limit: 8
t.text "parameters"
t.string "name"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.integer "organisation_id", limit: 8
end
create_table "stop_areas", force: true do |t|