diff options
| author | Guillaume | 2017-11-09 15:20:54 +0100 | 
|---|---|---|
| committer | Guillaume | 2017-11-09 15:21:01 +0100 | 
| commit | aafda8b5d8e6dbd80ed56fd469d5ada5dceb3a67 (patch) | |
| tree | 6e63632be099a8a86fcca69bcc2814efbff57c0a | |
| parent | 4dbe0a7b5acf4e244016d58d59a96aca36035263 (diff) | |
| download | chouette-core-aafda8b5d8e6dbd80ed56fd469d5ada5dceb3a67.tar.bz2 | |
add object_id_format to migrations, create module for call Referential, Line Referential, StopAreaReferential in models, add Enumerize in models Refs #4941
| -rw-r--r-- | app/models/chouette/company.rb | 1 | ||||
| -rw-r--r-- | app/models/chouette/journey_pattern.rb | 1 | ||||
| -rw-r--r-- | app/models/chouette/line.rb | 3 | ||||
| -rw-r--r-- | app/models/chouette/network.rb | 1 | ||||
| -rw-r--r-- | app/models/chouette/route.rb | 1 | ||||
| -rw-r--r-- | app/models/chouette/stop_area.rb | 3 | ||||
| -rw-r--r-- | app/models/chouette/stop_point.rb | 1 | ||||
| -rw-r--r-- | app/models/chouette/time_table.rb | 1 | ||||
| -rw-r--r-- | app/models/chouette/vehicle_journey.rb | 1 | ||||
| -rw-r--r-- | app/models/concerns/object_id_format.rb | 5 | ||||
| -rw-r--r-- | app/models/line_referential.rb | 2 | ||||
| -rw-r--r-- | app/models/referential.rb | 3 | ||||
| -rw-r--r-- | app/models/stop_area_referential.rb | 2 | ||||
| -rw-r--r-- | app/models/workbench.rb | 2 | ||||
| -rw-r--r-- | db/migrate/20171109100955_add_object_id_format_to_workbenches.rb | 5 | ||||
| -rw-r--r-- | db/migrate/20171109101523_add_object_id_format_to_referential.rb | 5 | ||||
| -rw-r--r-- | db/migrate/20171109101545_add_object_id_format_to_line_referential.rb | 5 | ||||
| -rw-r--r-- | db/migrate/20171109101605_add_object_id_format_to_stop_area_referential.rb | 5 | ||||
| -rw-r--r-- | db/schema.rb | 10 | 
19 files changed, 54 insertions, 3 deletions
| diff --git a/app/models/chouette/company.rb b/app/models/chouette/company.rb index a472020e1..ac7a7a0d9 100644 --- a/app/models/chouette/company.rb +++ b/app/models/chouette/company.rb @@ -2,6 +2,7 @@ class Chouette::Company < Chouette::ActiveRecord    include CompanyRestrictions    include StifCodifligneAttributesSupport    include LineReferentialSupport +  include ObjectIdFormat    has_many :lines diff --git a/app/models/chouette/journey_pattern.rb b/app/models/chouette/journey_pattern.rb index fa2a9c8bb..7c801794f 100644 --- a/app/models/chouette/journey_pattern.rb +++ b/app/models/chouette/journey_pattern.rb @@ -1,6 +1,7 @@  class Chouette::JourneyPattern < Chouette::TridentActiveRecord    include ChecksumSupport    include JourneyPatternRestrictions +  include ObjectIdFormat    # 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 0139bb6a4..ba48068c9 100644 --- a/app/models/chouette/line.rb +++ b/app/models/chouette/line.rb @@ -2,6 +2,7 @@ class Chouette::Line < Chouette::ActiveRecord    include StifCodifligneAttributesSupport    include LineRestrictions    include LineReferentialSupport +  include ObjectIdFormat    extend StifTransportModeEnumerations    extend StifTransportSubmodeEnumerations @@ -39,6 +40,8 @@ class Chouette::Line < Chouette::ActiveRecord    validates_presence_of :name +  alias_method :line_referential, :referential +    scope :by_text, ->(text) { where('lower(name) LIKE :t or lower(published_name) LIKE :t or lower(objectid) LIKE :t or lower(comment) LIKE :t or lower(number) LIKE :t',      t: "%#{text.downcase}%") } diff --git a/app/models/chouette/network.rb b/app/models/chouette/network.rb index 8df205789..69a0bd484 100644 --- a/app/models/chouette/network.rb +++ b/app/models/chouette/network.rb @@ -2,6 +2,7 @@ class Chouette::Network < Chouette::ActiveRecord    include StifCodifligneAttributesSupport    include NetworkRestrictions    include LineReferentialSupport +  include ObjectIdFormat    # 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 0bdccb36a..66743afbd 100644 --- a/app/models/chouette/route.rb +++ b/app/models/chouette/route.rb @@ -1,6 +1,7 @@  class Chouette::Route < Chouette::TridentActiveRecord    include RouteRestrictions    include ChecksumSupport +  include ObjectIdFormat    extend Enumerize    extend ActiveModel::Naming diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb index 43bc82f7f..de2d4b01c 100644 --- a/app/models/chouette/stop_area.rb +++ b/app/models/chouette/stop_area.rb @@ -10,6 +10,7 @@ class Chouette::StopArea < Chouette::ActiveRecord    include ProjectionFields    include StopAreaRestrictions    include StopAreaReferentialSupport +  include ObjectIdFormat    extend Enumerize    enumerize :area_type, in: %i(zdep zder zdlp zdlr lda) @@ -26,6 +27,8 @@ class Chouette::StopArea < Chouette::ActiveRecord    belongs_to :stop_area_referential    validates_presence_of :stop_area_referential_id +  alias_method :stop_area_referential, :referential +    acts_as_tree :foreign_key => 'parent_id', :order => "name"    attr_accessor :stop_area_type diff --git a/app/models/chouette/stop_point.rb b/app/models/chouette/stop_point.rb index 89c492b91..7490d175b 100644 --- a/app/models/chouette/stop_point.rb +++ b/app/models/chouette/stop_point.rb @@ -7,6 +7,7 @@ module Chouette      include ForBoardingEnumerations      include ForAlightingEnumerations +    include ObjectIdFormat      # 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 72496273e..868b82f59 100644 --- a/app/models/chouette/time_table.rb +++ b/app/models/chouette/time_table.rb @@ -1,6 +1,7 @@  class Chouette::TimeTable < Chouette::TridentActiveRecord    include ChecksumSupport    include TimeTableRestrictions +  include ObjectIdFormat    # FIXME http://jira.codehaus.org/browse/JRUBY-6358    self.primary_key = "id" diff --git a/app/models/chouette/vehicle_journey.rb b/app/models/chouette/vehicle_journey.rb index e534d2bde..ff7f4dc34 100644 --- a/app/models/chouette/vehicle_journey.rb +++ b/app/models/chouette/vehicle_journey.rb @@ -2,6 +2,7 @@ module Chouette    class VehicleJourney < TridentActiveRecord      include ChecksumSupport      include VehicleJourneyRestrictions +    include ObjectIdFormat      extend StifTransportModeEnumerations      # FIXME http://jira.codehaus.org/browse/JRUBY-6358      self.primary_key = "id" diff --git a/app/models/concerns/object_id_format.rb b/app/models/concerns/object_id_format.rb new file mode 100644 index 000000000..55b93ec81 --- /dev/null +++ b/app/models/concerns/object_id_format.rb @@ -0,0 +1,5 @@ +module ObjectIdFormat +  def object_id_format +    self.referential.object_id_format +  end +end diff --git a/app/models/line_referential.rb b/app/models/line_referential.rb index 8bc6adec3..b841ea6a9 100644 --- a/app/models/line_referential.rb +++ b/app/models/line_referential.rb @@ -1,5 +1,6 @@  class LineReferential < ActiveRecord::Base    extend StifTransportModeEnumerations +  extend Enumerize    has_many :line_referential_memberships    has_many :organisations, through: :line_referential_memberships @@ -9,6 +10,7 @@ class LineReferential < ActiveRecord::Base    has_many :networks, class_name: 'Chouette::Network'    has_many :line_referential_syncs, -> { order created_at: :desc }    has_many :workbenches +  enumerize :object_id_format, in: %w(netx netx_stif)    def add_member(organisation, options = {})      attributes = options.merge organisation: organisation diff --git a/app/models/referential.rb b/app/models/referential.rb index ed13cd077..37cad3c7d 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -1,5 +1,6 @@  class Referential < ActiveRecord::Base    include DataFormatEnumerations +  extend Enumerize    validates_presence_of :name    validates_presence_of :slug @@ -55,6 +56,8 @@ class Referential < ActiveRecord::Base    belongs_to :referential_suite +  enumerize :object_id_format, in: %w(netx netx_stif) +    scope :ready, -> { where(ready: true) }    scope :in_periode, ->(periode) { where(id: referential_ids_in_periode(periode)) }    scope :include_metadatas_lines, ->(line_ids) { where('referential_metadata.line_ids && ARRAY[?]::bigint[]', line_ids) } diff --git a/app/models/stop_area_referential.rb b/app/models/stop_area_referential.rb index dd206f9e9..a46dbd908 100644 --- a/app/models/stop_area_referential.rb +++ b/app/models/stop_area_referential.rb @@ -1,10 +1,12 @@  class StopAreaReferential < ActiveRecord::Base +  extend Enumerize    has_many :stop_area_referential_memberships    has_many :organisations, through: :stop_area_referential_memberships    has_many :stop_areas, class_name: 'Chouette::StopArea'    has_many :stop_area_referential_syncs, -> {order created_at: :desc}    has_many :workbenches +  enumerize :object_id_format, in: %w(netx netx_stif)    def add_member(organisation, options = {})      attributes = options.merge organisation: organisation diff --git a/app/models/workbench.rb b/app/models/workbench.rb index c304e8ba9..9b1bb7e09 100644 --- a/app/models/workbench.rb +++ b/app/models/workbench.rb @@ -1,8 +1,10 @@  class Workbench < ActiveRecord::Base +  extend Enumerize    belongs_to :organisation    belongs_to :line_referential    belongs_to :stop_area_referential    belongs_to :output, class_name: 'ReferentialSuite' +  enumerize :object_id_format, in: %w(netx netx_stif)    has_many :lines, -> (workbench) { Stif::MyWorkbenchScopes.new(workbench).line_scope(self) }, through: :line_referential    has_many :networks, through: :line_referential diff --git a/db/migrate/20171109100955_add_object_id_format_to_workbenches.rb b/db/migrate/20171109100955_add_object_id_format_to_workbenches.rb new file mode 100644 index 000000000..0e5e57643 --- /dev/null +++ b/db/migrate/20171109100955_add_object_id_format_to_workbenches.rb @@ -0,0 +1,5 @@ +class AddObjectIdFormatToWorkbenches < ActiveRecord::Migration +  def change +    add_column :workbenches, :objectid_format, :string +  end +end diff --git a/db/migrate/20171109101523_add_object_id_format_to_referential.rb b/db/migrate/20171109101523_add_object_id_format_to_referential.rb new file mode 100644 index 000000000..fed630b75 --- /dev/null +++ b/db/migrate/20171109101523_add_object_id_format_to_referential.rb @@ -0,0 +1,5 @@ +class AddObjectIdFormatToReferential < ActiveRecord::Migration +  def change +    add_column :referentials, :objectid_format, :string +  end +end diff --git a/db/migrate/20171109101545_add_object_id_format_to_line_referential.rb b/db/migrate/20171109101545_add_object_id_format_to_line_referential.rb new file mode 100644 index 000000000..5d2fc9f4f --- /dev/null +++ b/db/migrate/20171109101545_add_object_id_format_to_line_referential.rb @@ -0,0 +1,5 @@ +class AddObjectIdFormatToLineReferential < ActiveRecord::Migration +  def change +    add_column :line_referentials, :objectid_format, :string +  end +end diff --git a/db/migrate/20171109101605_add_object_id_format_to_stop_area_referential.rb b/db/migrate/20171109101605_add_object_id_format_to_stop_area_referential.rb new file mode 100644 index 000000000..ffa77e2ed --- /dev/null +++ b/db/migrate/20171109101605_add_object_id_format_to_stop_area_referential.rb @@ -0,0 +1,5 @@ +class AddObjectIdFormatToStopAreaReferential < ActiveRecord::Migration +  def change +    add_column :stop_area_referentials, :objectid_format, :string +  end +end diff --git a/db/schema.rb b/db/schema.rb index 050e81ad5..d71a2def3 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: 20171106111448) do +ActiveRecord::Schema.define(version: 20171109101605) do    # These are extensions that must be enabled in order to support this database    enable_extension "plpgsql" @@ -408,9 +408,9 @@ ActiveRecord::Schema.define(version: 20171106111448) do      t.string   "type"      t.integer  "parent_id",             limit: 8      t.string   "parent_type" +    t.datetime "notified_parent_at"      t.integer  "current_step",                    default: 0      t.integer  "total_steps",                     default: 0 -    t.datetime "notified_parent_at"      t.string   "creator"    end @@ -503,7 +503,8 @@ ActiveRecord::Schema.define(version: 20171106111448) do      t.string   "name"      t.datetime "created_at"      t.datetime "updated_at" -    t.integer  "sync_interval", default: 1 +    t.integer  "sync_interval",   default: 1 +    t.string   "objectid_format"    end    create_table "lines", id: :bigserial, force: :cascade do |t| @@ -647,6 +648,7 @@ ActiveRecord::Schema.define(version: 20171106111448) do      t.integer  "created_from_id",          limit: 8      t.boolean  "ready",                              default: false      t.integer  "referential_suite_id",     limit: 8 +    t.string   "objectid_format"    end    add_index "referentials", ["created_from_id"], name: "index_referentials_on_created_from_id", using: :btree @@ -746,6 +748,7 @@ ActiveRecord::Schema.define(version: 20171106111448) do      t.string   "name"      t.datetime "created_at"      t.datetime "updated_at" +    t.string   "objectid_format"    end    create_table "stop_areas", id: :bigserial, force: :cascade do |t| @@ -984,6 +987,7 @@ ActiveRecord::Schema.define(version: 20171106111448) do      t.integer  "line_referential_id",      limit: 8      t.integer  "stop_area_referential_id", limit: 8      t.integer  "output_id",                limit: 8 +    t.string   "objectid_format"    end    add_index "workbenches", ["line_referential_id"], name: "index_workbenches_on_line_referential_id", using: :btree | 
