enju_oai 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. data/app/views/manifestations/list_identifiers.oai.builder +1 -1
  2. data/app/views/manifestations/list_records.oai.builder +1 -1
  3. data/lib/enju_oai/oai_controller.rb +32 -0
  4. data/lib/enju_oai/version.rb +1 -1
  5. data/spec/controllers/manifestations_controller_spec.rb +45 -0
  6. data/spec/dummy/README.rdoc +261 -0
  7. data/spec/dummy/Rakefile +7 -0
  8. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  9. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  10. data/spec/dummy/app/controllers/application_controller.rb +76 -0
  11. data/spec/dummy/app/controllers/manifestations_controller.rb +519 -0
  12. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  13. data/spec/dummy/app/models/ability.rb +29 -0
  14. data/spec/dummy/app/models/carrier_type.rb +33 -0
  15. data/spec/dummy/app/models/create.rb +38 -0
  16. data/spec/dummy/app/models/exemplify.rb +45 -0
  17. data/spec/dummy/app/models/item.rb +276 -0
  18. data/spec/dummy/app/models/manifestation.rb +631 -0
  19. data/spec/dummy/app/models/patron.rb +290 -0
  20. data/spec/dummy/app/models/produce.rb +39 -0
  21. data/spec/dummy/app/models/realize.rb +38 -0
  22. data/spec/dummy/app/models/role.rb +46 -0
  23. data/spec/dummy/app/models/search_engine.rb +51 -0
  24. data/spec/dummy/app/models/user.rb +94 -0
  25. data/spec/dummy/app/models/user_has_role.rb +4 -0
  26. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  27. data/spec/dummy/config/application.rb +57 -0
  28. data/spec/dummy/config/boot.rb +10 -0
  29. data/spec/dummy/config/configatron/cucumber.rb +4 -0
  30. data/spec/dummy/config/configatron/defaults.rb +28 -0
  31. data/spec/dummy/config/configatron/development.rb +4 -0
  32. data/spec/dummy/config/configatron/production.rb.sample +12 -0
  33. data/spec/dummy/config/configatron/test.rb +7 -0
  34. data/spec/dummy/config/database.yml +25 -0
  35. data/spec/dummy/config/environment.rb +5 -0
  36. data/spec/dummy/config/environments/development.rb +37 -0
  37. data/spec/dummy/config/environments/production.rb +67 -0
  38. data/spec/dummy/config/environments/test.rb +37 -0
  39. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  40. data/spec/dummy/config/initializers/configatron.rb +2 -0
  41. data/spec/dummy/config/initializers/devise.rb +209 -0
  42. data/spec/dummy/config/initializers/inflections.rb +15 -0
  43. data/spec/dummy/config/initializers/mime_types.rb +14 -0
  44. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  45. data/spec/dummy/config/initializers/session_store.rb +8 -0
  46. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  47. data/spec/dummy/config/locales/en.yml +5 -0
  48. data/spec/dummy/config/routes.rb +60 -0
  49. data/spec/dummy/config.ru +4 -0
  50. data/spec/dummy/db/migrate/001_create_patrons.rb +53 -0
  51. data/spec/dummy/db/migrate/002_devise_create_users.rb +71 -0
  52. data/spec/dummy/db/migrate/005_create_manifestations.rb +59 -0
  53. data/spec/dummy/db/migrate/006_create_items.rb +28 -0
  54. data/spec/dummy/db/migrate/012_create_owns.rb +14 -0
  55. data/spec/dummy/db/migrate/015_create_creates.rb +14 -0
  56. data/spec/dummy/db/migrate/041_create_roles.rb +13 -0
  57. data/spec/dummy/db/migrate/047_create_produces.rb +14 -0
  58. data/spec/dummy/db/migrate/059_create_libraries.rb +30 -0
  59. data/spec/dummy/db/migrate/073_create_carrier_types.rb +11 -0
  60. data/spec/dummy/db/migrate/077_create_user_groups.rb +12 -0
  61. data/spec/dummy/db/migrate/080_create_library_groups.rb +21 -0
  62. data/spec/dummy/db/migrate/112_create_frequencies.rb +12 -0
  63. data/spec/dummy/db/migrate/117_create_form_of_works.rb +12 -0
  64. data/spec/dummy/db/migrate/20080830154109_create_realizes.rb +15 -0
  65. data/spec/dummy/db/migrate/20080830172106_create_exemplifies.rb +15 -0
  66. data/spec/dummy/db/migrate/20080905191442_create_patron_types.rb +12 -0
  67. data/spec/dummy/db/migrate/20081023092436_create_search_engines.rb +17 -0
  68. data/spec/dummy/db/migrate/20081025083323_create_countries.rb +28 -0
  69. data/spec/dummy/db/migrate/20081025083905_create_languages.rb +23 -0
  70. data/spec/dummy/db/migrate/20090719201843_create_extents.rb +12 -0
  71. data/spec/dummy/db/migrate/20090720091106_create_medium_of_performances.rb +12 -0
  72. data/spec/dummy/db/migrate/20090720091429_create_content_types.rb +12 -0
  73. data/spec/dummy/db/migrate/20090812151902_create_patron_relationship_types.rb +12 -0
  74. data/spec/dummy/db/migrate/20091025080447_create_licenses.rb +12 -0
  75. data/spec/dummy/db/migrate/20091202124834_create_versions.rb +18 -0
  76. data/spec/dummy/db/migrate/20100211105551_add_admin_networks_to_library_group.rb +9 -0
  77. data/spec/dummy/db/migrate/20100326024214_add_date_index_to_resource.rb +11 -0
  78. data/spec/dummy/db/migrate/20100502171926_add_latitude_and_longitude_to_library.rb +11 -0
  79. data/spec/dummy/db/migrate/20100525124311_create_manifestation_relationships.rb +13 -0
  80. data/spec/dummy/db/migrate/20100606065209_create_user_has_roles.rb +12 -0
  81. data/spec/dummy/db/migrate/20100606073747_create_patron_relationships.rb +13 -0
  82. data/spec/dummy/db/migrate/20100607044753_create_manifestation_relationship_types.rb +12 -0
  83. data/spec/dummy/db/migrate/20100627193848_add_enju_access_key_to_user.rb +10 -0
  84. data/spec/dummy/db/migrate/20100814091104_add_position_to_patron_relationship.rb +11 -0
  85. data/spec/dummy/db/migrate/20100919121500_drop_user_email_unique_index.rb +11 -0
  86. data/spec/dummy/db/migrate/20101103090330_add_title_to_patron.rb +9 -0
  87. data/spec/dummy/db/migrate/20101103090457_rename_manifestation_identifier_to_identifier.rb +9 -0
  88. data/spec/dummy/db/migrate/20101212070145_add_acquired_at_to_item.rb +9 -0
  89. data/spec/dummy/db/migrate/20101228081401_rename_postal_code_to_zip_code.rb +11 -0
  90. data/spec/dummy/db/migrate/20110115022329_add_position_to_library_group.rb +9 -0
  91. data/spec/dummy/db/migrate/20110222073537_add_url_to_library_group.rb +9 -0
  92. data/spec/dummy/db/migrate/20110301035123_add_pub_date_to_manifestation.rb +9 -0
  93. data/spec/dummy/db/migrate/20110301121550_add_birth_date_and_death_date_to_patron.rb +11 -0
  94. data/spec/dummy/db/migrate/20110318183304_add_valid_period_for_new_user_to_user_group.rb +13 -0
  95. data/spec/dummy/db/migrate/20110619064807_add_edition_string_to_manifestation.rb +9 -0
  96. data/spec/dummy/db/migrate/20110627122938_add_number_of_day_to_notify_overdue_to_user_group.rb +13 -0
  97. data/spec/dummy/db/migrate/20110916053430_rename_manifestation_number_list_to_number_string.rb +13 -0
  98. data/spec/dummy/db/migrate/20110916091020_add_volume_number_to_manifestation.rb +13 -0
  99. data/spec/dummy/db/migrate/20110927135845_add_missing_since_to_item.rb +9 -0
  100. data/spec/dummy/db/migrate/20111103221239_rename_manifestation_identifier_to_manifestation_identifier.rb +9 -0
  101. data/spec/dummy/db/migrate/20111124110059_create_create_types.rb +12 -0
  102. data/spec/dummy/db/migrate/20111124110319_create_realize_types.rb +12 -0
  103. data/spec/dummy/db/migrate/20111124110355_create_produce_types.rb +12 -0
  104. data/spec/dummy/db/migrate/20111124112131_add_create_type_to_create.rb +7 -0
  105. data/spec/dummy/db/migrate/20120105074911_add_isil_to_library.rb +5 -0
  106. data/spec/dummy/db/migrate/20120319120638_add_content_type_id_to_manifestation.rb +6 -0
  107. data/spec/dummy/db/migrate/20120410104851_add_year_of_publication_to_manifestation.rb +5 -0
  108. data/spec/dummy/db/migrate/20120413225628_add_fingerprint_to_manifestation.rb +5 -0
  109. data/spec/dummy/db/migrate/20120415164821_add_attachment_meta_to_manifestation.rb +5 -0
  110. data/spec/dummy/db/migrate/20120418081407_add_month_of_publication_to_manifestation.rb +5 -0
  111. data/spec/dummy/db/migrate/20120426034355_add_unique_index_to_item_identifier.rb +11 -0
  112. data/spec/dummy/db/migrate/20120426042730_add_unique_index_to_manifestation_identifier.rb +11 -0
  113. data/spec/dummy/db/schema.rb +564 -0
  114. data/spec/dummy/db/test.sqlite3 +0 -0
  115. data/spec/dummy/lib/enju_leaf/calculate_stat.rb +30 -0
  116. data/spec/dummy/lib/enju_leaf/expire_editable_fragment.rb +30 -0
  117. data/spec/dummy/lib/enju_leaf/expire_fragment_cache.rb +17 -0
  118. data/spec/dummy/lib/enju_leaf/import_file.rb +13 -0
  119. data/spec/dummy/lib/enju_leaf/localized_name.rb +13 -0
  120. data/spec/dummy/lib/enju_leaf/master_model.rb +19 -0
  121. data/spec/dummy/lib/enju_leaf/url_validator.rb +10 -0
  122. data/spec/dummy/lib/enju_leaf.rb +8 -0
  123. data/spec/dummy/public/404.html +26 -0
  124. data/spec/dummy/public/422.html +26 -0
  125. data/spec/dummy/public/500.html +25 -0
  126. data/spec/dummy/public/favicon.ico +0 -0
  127. data/spec/dummy/script/rails +6 -0
  128. data/spec/dummy/tmp/cache/4F7/F90/default_role +0 -0
  129. data/spec/dummy/tmp/cache/6E4/420/search_engine_all +0 -0
  130. data/spec/factories/manifestation.rb +6 -0
  131. data/spec/factories/user.rb +34 -0
  132. data/spec/fixtures/carrier_types.yml +51 -0
  133. data/spec/fixtures/creates.yml +66 -0
  134. data/spec/fixtures/exemplifies.yml +156 -0
  135. data/spec/fixtures/items.yml +262 -0
  136. data/spec/fixtures/libraries.yml +109 -0
  137. data/spec/fixtures/library_groups.yml +36 -0
  138. data/spec/fixtures/manifestations.yml +2024 -0
  139. data/spec/fixtures/patron_types.yml +41 -0
  140. data/spec/fixtures/patrons.yml +338 -0
  141. data/spec/fixtures/produces.yml +150 -0
  142. data/spec/fixtures/realizes.yml +87 -0
  143. data/spec/fixtures/roles.yml +21 -0
  144. data/spec/fixtures/user_has_roles.yml +41 -0
  145. data/spec/fixtures/users.yml +93 -0
  146. data/spec/spec_helper.rb +38 -0
  147. data/spec/support/controller_macros.rb +48 -0
  148. data/spec/support/devise.rb +4 -0
  149. metadata +290 -6
  150. data/test/enju_oai_test.rb +0 -7
  151. data/test/test_helper.rb +0 -15
@@ -0,0 +1,290 @@
1
+ # -*- encoding: utf-8 -*-
2
+ class Patron < ActiveRecord::Base
3
+ scope :readable_by, lambda{|user| {:conditions => ['required_role_id <= ?', user.try(:user_has_role).try(:role_id) || Role.where(:name => 'Guest').select(:id).first.id]}}
4
+ has_many :creates, :dependent => :destroy
5
+ has_many :works, :through => :creates
6
+ has_many :realizes, :dependent => :destroy
7
+ has_many :expressions, :through => :realizes
8
+ has_many :produces, :dependent => :destroy
9
+ has_many :manifestations, :through => :produces
10
+ has_many :children, :foreign_key => 'parent_id', :class_name => 'PatronRelationship', :dependent => :destroy
11
+ has_many :parents, :foreign_key => 'child_id', :class_name => 'PatronRelationship', :dependent => :destroy
12
+ has_many :derived_patrons, :through => :children, :source => :child
13
+ has_many :original_patrons, :through => :parents, :source => :parent
14
+ has_many :picture_files, :as => :picture_attachable, :dependent => :destroy
15
+ has_many :donates
16
+ has_many :donated_items, :through => :donates, :source => :item
17
+ has_many :owns, :dependent => :destroy
18
+ has_many :items, :through => :owns
19
+ if defined?(EnjuResourceMerge)
20
+ has_many :patron_merges, :dependent => :destroy
21
+ has_many :patron_merge_lists, :through => :patron_merges
22
+ end
23
+ #belongs_to :user
24
+ belongs_to :patron_type
25
+ belongs_to :required_role, :class_name => 'Role', :foreign_key => 'required_role_id', :validate => true
26
+ belongs_to :language
27
+ belongs_to :country
28
+ has_one :patron_import_result
29
+
30
+ validates_presence_of :language, :patron_type, :country
31
+ validates_associated :language, :patron_type, :country
32
+ validates :full_name, :presence => true, :length => {:maximum => 255}
33
+ #validates :user_id, :uniqueness => true, :allow_nil => true
34
+ validates :birth_date, :format => {:with => /^\d+(-\d{0,2}){0,2}$/}, :allow_blank => true
35
+ validates :death_date, :format => {:with => /^\d+(-\d{0,2}){0,2}$/}, :allow_blank => true
36
+ validates :email, :format => {:with => /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i}, :allow_blank => true
37
+ validate :check_birth_date
38
+ before_validation :set_role_and_name, :on => :create
39
+ before_save :set_date_of_birth, :set_date_of_death
40
+
41
+ searchable do
42
+ text :name, :place, :address_1, :address_2, :other_designation, :note
43
+ string :zip_code_1
44
+ string :zip_code_2
45
+ #string :username do
46
+ # user.username if user
47
+ #end
48
+ time :created_at
49
+ time :updated_at
50
+ time :date_of_birth
51
+ time :date_of_death
52
+ #string :user
53
+ integer :work_ids, :multiple => true
54
+ integer :expression_ids, :multiple => true
55
+ integer :manifestation_ids, :multiple => true
56
+ integer :patron_merge_list_ids, :multiple => true if defined?(EnjuResourceMerge)
57
+ integer :original_patron_ids, :multiple => true
58
+ integer :required_role_id
59
+ integer :patron_type_id
60
+ end
61
+
62
+ def self.per_page
63
+ 10
64
+ end
65
+
66
+ def set_role_and_name
67
+ self.required_role = Role.where(:name => 'Librarian').first if self.required_role_id.nil?
68
+ set_full_name
69
+ end
70
+
71
+ def set_full_name
72
+ if self.full_name.blank?
73
+ if self.last_name.to_s.strip and self.first_name.to_s.strip and configatron.family_name_first == true
74
+ self.full_name = [last_name, middle_name, first_name].compact.join(" ").to_s.strip
75
+ else
76
+ self.full_name = [first_name, last_name, middle_name].compact.join(" ").to_s.strip
77
+ end
78
+ end
79
+ if self.full_name_transcription.blank?
80
+ self.full_name_transcription = [last_name_transcription, middle_name_transcription, first_name_transcription].join(" ").to_s.strip
81
+ end
82
+ [self.full_name, self.full_name_transcription]
83
+ end
84
+
85
+ def set_date_of_birth
86
+ return if birth_date.blank?
87
+ begin
88
+ date = Time.zone.parse("#{birth_date}")
89
+ rescue ArgumentError
90
+ begin
91
+ date = Time.zone.parse("#{birth_date}-01")
92
+ rescue ArgumentError
93
+ begin
94
+ date = Time.zone.parse("#{birth_date}-01-01")
95
+ rescue
96
+ nil
97
+ end
98
+ end
99
+ end
100
+ self.date_of_birth = date
101
+ end
102
+
103
+ def set_date_of_death
104
+ return if death_date.blank?
105
+ begin
106
+ date = Time.zone.parse("#{death_date}")
107
+ rescue ArgumentError
108
+ begin
109
+ date = Time.zone.parse("#{death_date}-01")
110
+ rescue ArgumentError
111
+ begin
112
+ date = Time.zone.parse("#{death_date}-01-01")
113
+ rescue
114
+ nil
115
+ end
116
+ end
117
+ end
118
+
119
+ self.date_of_death = date
120
+ end
121
+
122
+ def check_birth_date
123
+ if date_of_birth.present? and date_of_death.present?
124
+ if date_of_birth > date_of_death
125
+ errors.add(:birth_date)
126
+ errors.add(:death_date)
127
+ end
128
+ end
129
+ end
130
+
131
+ #def full_name_generate
132
+ # # TODO: 日本人以外は?
133
+ # name = []
134
+ # name << self.last_name.to_s.strip
135
+ # name << self.middle_name.to_s.strip unless self.middle_name.blank?
136
+ # name << self.first_name.to_s.strip
137
+ # name << self.corporate_name.to_s.strip
138
+ # name.join(" ").strip
139
+ #end
140
+
141
+ def full_name_without_space
142
+ full_name.gsub(/[\s,]/, "")
143
+ # # TODO: 日本人以外は?
144
+ # name = []
145
+ # name << self.last_name.to_s.strip
146
+ # name << self.middle_name.to_s.strip
147
+ # name << self.first_name.to_s.strip
148
+ # name << self.corporate_name.to_s.strip
149
+ # name.join("").strip
150
+ end
151
+
152
+ def full_name_transcription_without_space
153
+ full_name_transcription.to_s.gsub(/\s/, "")
154
+ end
155
+
156
+ def full_name_alternative_without_space
157
+ full_name_alternative.to_s.gsub(/\s/, "")
158
+ end
159
+
160
+ def name
161
+ name = []
162
+ name << full_name.to_s.strip
163
+ name << full_name_transcription.to_s.strip
164
+ name << full_name_alternative.to_s.strip
165
+ name << full_name_without_space
166
+ #name << full_name_transcription_without_space
167
+ #name << full_name_alternative_without_space
168
+ #name << full_name.wakati rescue nil
169
+ #name << full_name_transcription.wakati rescue nil
170
+ #name << full_name_alternative.wakati rescue nil
171
+ name
172
+ end
173
+
174
+ def date
175
+ if date_of_birth
176
+ if date_of_death
177
+ "#{date_of_birth} - #{date_of_death}"
178
+ else
179
+ "#{date_of_birth} -"
180
+ end
181
+ end
182
+ end
183
+
184
+ def creator?(resource)
185
+ resource.creators.include?(self)
186
+ end
187
+
188
+ def publisher?(resource)
189
+ resource.publishers.include?(self)
190
+ end
191
+
192
+ def created(work)
193
+ creates.where(:work_id => work.id).first
194
+ end
195
+
196
+ def realized(expression)
197
+ realizes.where(:expression_id => expression.id).first
198
+ end
199
+
200
+ def produced(manifestation)
201
+ produces.where(:manifestation_id => manifestation.id).first
202
+ end
203
+
204
+ def owned(item)
205
+ owns.where(:item_id => item.id)
206
+ end
207
+
208
+ def self.import_patrons(patron_lists)
209
+ patrons = []
210
+ patron_lists.each do |patron_list|
211
+ name_and_role = patron_list[:full_name].split('||')
212
+ patron = Patron.where(:full_name => name_and_role[0]).first
213
+ role_type = name_and_role[1].to_s.strip
214
+ unless patron
215
+ patron = Patron.new(
216
+ :full_name => name_and_role[0],
217
+ :full_name_transcription => patron_list[:full_name_transcription],
218
+ :language_id => 1
219
+ )
220
+ patron.required_role = Role.where(:name => 'Guest').first
221
+ patron.save
222
+ end
223
+ patrons << patron
224
+ end
225
+ patrons
226
+ end
227
+
228
+ def patrons
229
+ self.original_patrons + self.derived_patrons
230
+ end
231
+
232
+ def user
233
+ # TODO: 外部サービスから取得する
234
+ end
235
+ end
236
+
237
+
238
+ # == Schema Information
239
+ #
240
+ # Table name: patrons
241
+ #
242
+ # id :integer not null, primary key
243
+ # user_id :integer
244
+ # last_name :string(255)
245
+ # middle_name :string(255)
246
+ # first_name :string(255)
247
+ # last_name_transcription :string(255)
248
+ # middle_name_transcription :string(255)
249
+ # first_name_transcription :string(255)
250
+ # corporate_name :string(255)
251
+ # corporate_name_transcription :string(255)
252
+ # full_name :string(255)
253
+ # full_name_transcription :text
254
+ # full_name_alternative :text
255
+ # created_at :datetime
256
+ # updated_at :datetime
257
+ # deleted_at :datetime
258
+ # zip_code_1 :string(255)
259
+ # zip_code_2 :string(255)
260
+ # address_1 :text
261
+ # address_2 :text
262
+ # address_1_note :text
263
+ # address_2_note :text
264
+ # telephone_number_1 :string(255)
265
+ # telephone_number_2 :string(255)
266
+ # fax_number_1 :string(255)
267
+ # fax_number_2 :string(255)
268
+ # other_designation :text
269
+ # place :text
270
+ # street :text
271
+ # locality :text
272
+ # region :text
273
+ # date_of_birth :datetime
274
+ # date_of_death :datetime
275
+ # language_id :integer default(1), not null
276
+ # country_id :integer default(1), not null
277
+ # patron_type_id :integer default(1), not null
278
+ # lock_version :integer default(0), not null
279
+ # note :text
280
+ # required_role_id :integer default(1), not null
281
+ # required_score :integer default(0), not null
282
+ # state :string(255)
283
+ # email :text
284
+ # url :text
285
+ # full_name_alternative_transcription :text
286
+ # title :string(255)
287
+ # birth_date :string(255)
288
+ # death_date :string(255)
289
+ #
290
+
@@ -0,0 +1,39 @@
1
+ class Produce < ActiveRecord::Base
2
+ belongs_to :patron
3
+ belongs_to :manifestation
4
+ belongs_to :produce_type
5
+ delegate :original_title, :to => :manifestation, :prefix => true
6
+
7
+ validates_associated :patron, :manifestation
8
+ validates_presence_of :patron, :manifestation
9
+ validates_uniqueness_of :manifestation_id, :scope => :patron_id
10
+ after_save :reindex
11
+ after_destroy :reindex
12
+
13
+ acts_as_list :scope => :manifestation
14
+
15
+ def self.per_page
16
+ 10
17
+ end
18
+
19
+ def reindex
20
+ patron.try(:index)
21
+ manifestation.try(:index)
22
+ end
23
+ end
24
+
25
+
26
+ # == Schema Information
27
+ #
28
+ # Table name: produces
29
+ #
30
+ # id :integer not null, primary key
31
+ # patron_id :integer not null
32
+ # manifestation_id :integer not null
33
+ # position :integer
34
+ # type :string(255)
35
+ # created_at :datetime
36
+ # updated_at :datetime
37
+ # produce_type_id :integer
38
+ #
39
+
@@ -0,0 +1,38 @@
1
+ class Realize < ActiveRecord::Base
2
+ belongs_to :patron
3
+ belongs_to :expression, :class_name => 'Manifestation', :foreign_key => 'expression_id'
4
+ belongs_to :realize_type
5
+
6
+ validates_associated :patron, :expression
7
+ validates_presence_of :patron, :expression
8
+ validates_uniqueness_of :expression_id, :scope => :patron_id
9
+ after_save :reindex
10
+ after_destroy :reindex
11
+
12
+ acts_as_list :scope => :expression
13
+
14
+ def self.per_page
15
+ 10
16
+ end
17
+
18
+ def reindex
19
+ patron.try(:index)
20
+ expression.try(:index)
21
+ end
22
+ end
23
+
24
+
25
+ # == Schema Information
26
+ #
27
+ # Table name: realizes
28
+ #
29
+ # id :integer not null, primary key
30
+ # patron_id :integer not null
31
+ # expression_id :integer not null
32
+ # position :integer
33
+ # type :string(255)
34
+ # created_at :datetime
35
+ # updated_at :datetime
36
+ # realize_type_id :integer
37
+ #
38
+
@@ -0,0 +1,46 @@
1
+ class Role < ActiveRecord::Base
2
+ include MasterModel
3
+ default_scope :order => "roles.position"
4
+ has_many :user_has_roles
5
+ has_many :users, :through => :user_has_roles
6
+ after_save :clear_all_cache
7
+ after_destroy :clear_all_cache
8
+
9
+ extend FriendlyId
10
+ friendly_id :name
11
+
12
+ def localized_name
13
+ display_name.localize
14
+ end
15
+
16
+ def self.all_cache
17
+ if Rails.env == 'production'
18
+ Rails.cache.fetch('role_all'){Role.select(:name).all}
19
+ else
20
+ Role.select(:name)
21
+ end
22
+ end
23
+
24
+ def clear_all_cache
25
+ Rails.cache.delete('role_all')
26
+ end
27
+
28
+ def self.default_role
29
+ Rails.cache.fetch('default_role'){Role.find('Guest')}
30
+ end
31
+ end
32
+
33
+ # == Schema Information
34
+ #
35
+ # Table name: roles
36
+ #
37
+ # id :integer not null, primary key
38
+ # name :string(255) not null
39
+ # display_name :string(255)
40
+ # note :text
41
+ # created_at :datetime
42
+ # updated_at :datetime
43
+ # score :integer default(0), not null
44
+ # position :integer
45
+ #
46
+
@@ -0,0 +1,51 @@
1
+ class SearchEngine < ActiveRecord::Base
2
+ default_scope :order => "position"
3
+ belongs_to :library_group, :validate => true
4
+ acts_as_list
5
+
6
+ validates :name, :presence => true
7
+ validates :query_param, :presence => true
8
+ validates :http_method, :presence => true, :inclusion => %w(get post)
9
+ validates :url, :presence => true, :url => true, :length => {:maximum => 255}
10
+ validates :base_url, :presence => true, :url => true, :length => {:maximum => 255}
11
+ after_save :clear_all_cache
12
+ after_destroy :clear_all_cache
13
+
14
+ def self.per_page
15
+ 10
16
+ end
17
+
18
+ def clear_all_cache
19
+ Rails.cache.delete('search_engine_all')
20
+ end
21
+
22
+ def search_params(query)
23
+ params = {}
24
+ if self.additional_param
25
+ self.additional_param.gsub('{query}', query).to_s.split.each do |param|
26
+ p = param.split("=")
27
+ params[p[0].to_sym] = p[1]
28
+ end
29
+ return params
30
+ end
31
+ end
32
+ end
33
+
34
+ # == Schema Information
35
+ #
36
+ # Table name: search_engines
37
+ #
38
+ # id :integer not null, primary key
39
+ # name :string(255) not null
40
+ # display_name :text
41
+ # url :string(255) not null
42
+ # base_url :text not null
43
+ # http_method :text not null
44
+ # query_param :text not null
45
+ # additional_param :text
46
+ # note :text
47
+ # position :integer
48
+ # created_at :datetime
49
+ # updated_at :datetime
50
+ #
51
+
@@ -0,0 +1,94 @@
1
+ class User < ActiveRecord::Base
2
+ # Include default devise modules. Others available are:
3
+ # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
4
+ devise :database_authenticatable, :registerable,
5
+ :recoverable, :rememberable, :trackable, :validatable
6
+
7
+ # Setup accessible (or protected) attributes for your model
8
+ attr_accessible :email, :password, :password_confirmation, :remember_me
9
+
10
+ has_one :patron
11
+ has_one :user_has_role
12
+ has_one :role, :through => :user_has_role
13
+ belongs_to :user_group
14
+ belongs_to :required_role, :class_name => 'Role', :foreign_key => 'required_role_id'
15
+ has_many :checkouts, :dependent => :nullify
16
+ has_many :reserves, :dependent => :destroy
17
+ has_many :reserved_manifestations, :through => :reserves, :source => :manifestation
18
+ has_many :checkout_stat_has_users
19
+ has_many :user_checkout_stats, :through => :checkout_stat_has_users
20
+ has_many :reserve_stat_has_users
21
+ has_many :user_reserve_stats, :through => :reserve_stat_has_users
22
+ has_many :baskets, :dependent => :destroy
23
+ belongs_to :library
24
+
25
+ before_destroy :check_item_before_destroy
26
+
27
+ extend FriendlyId
28
+ friendly_id :username
29
+
30
+ def check_item_before_destroy
31
+ # TODO: 貸出記録を残す場合
32
+ if checkouts.size > 0
33
+ raise 'This user has items still checked out.'
34
+ end
35
+ end
36
+
37
+ def reset_checkout_icalendar_token
38
+ self.checkout_icalendar_token = Devise.friendly_token
39
+ end
40
+
41
+ def delete_checkout_icalendar_token
42
+ self.checkout_icalendar_token = nil
43
+ end
44
+
45
+ def checked_item_count
46
+ checkout_count = {}
47
+ CheckoutType.all.each do |checkout_type|
48
+ # 資料種別ごとの貸出中の冊数を計算
49
+ checkout_count[:"#{checkout_type.name}"] = self.checkouts.count_by_sql(["
50
+ SELECT count(item_id) FROM checkouts
51
+ WHERE item_id IN (
52
+ SELECT id FROM items
53
+ WHERE checkout_type_id = ?
54
+ )
55
+ AND user_id = ? AND checkin_id IS NULL", checkout_type.id, self.id]
56
+ )
57
+ end
58
+ return checkout_count
59
+ end
60
+
61
+ def reached_reservation_limit?(manifestation)
62
+ return true if self.user_group.user_group_has_checkout_types.available_for_carrier_type(manifestation.carrier_type).where(:user_group_id => self.user_group.id).collect(&:reservation_limit).max.to_i <= self.reserves.waiting.size
63
+ false
64
+ end
65
+
66
+ def has_role?(role_in_question)
67
+ return false unless role
68
+ return true if role.name == role_in_question
69
+ case role.name
70
+ when 'Administrator'
71
+ return true
72
+ when 'Librarian'
73
+ return true if role_in_question == 'User'
74
+ else
75
+ false
76
+ end
77
+ end
78
+
79
+ if defined?(EnjuMessage)
80
+ has_many :sent_messages, :foreign_key => 'sender_id', :class_name => 'Message'
81
+ has_many :received_messages, :foreign_key => 'receiver_id', :class_name => 'Message'
82
+
83
+ def send_message(status, options = {})
84
+ MessageRequest.transaction do
85
+ request = MessageRequest.new
86
+ request.sender = User.find(1)
87
+ request.receiver = self
88
+ request.message_template = MessageTemplate.localized_template(status, self.locale)
89
+ request.save_message_body(options)
90
+ request.sm_send_message!
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,4 @@
1
+ class UserHasRole < ActiveRecord::Base
2
+ belongs_to :user
3
+ belongs_to :role
4
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag "application", :media => "all" %>
6
+ <%= javascript_include_tag "application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,57 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ Bundler.require
6
+ require "enju_oai"
7
+
8
+ module Dummy
9
+ class Application < Rails::Application
10
+ # Settings in config/environments/* take precedence over those specified here.
11
+ # Application configuration should go into files in config/initializers
12
+ # -- all .rb files in that directory are automatically loaded.
13
+
14
+ # Custom directories with classes and modules you want to be autoloadable.
15
+ # config.autoload_paths += %W(#{config.root}/extras)
16
+
17
+ # Only load the plugins named here, in the order given (default is alphabetical).
18
+ # :all can be used as a placeholder for all plugins not explicitly named.
19
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
20
+
21
+ # Activate observers that should always be running.
22
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
23
+
24
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
25
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
26
+ # config.time_zone = 'Central Time (US & Canada)'
27
+
28
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
29
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
30
+ # config.i18n.default_locale = :de
31
+
32
+ # Configure the default encoding used in templates for Ruby 1.9.
33
+ config.encoding = "utf-8"
34
+
35
+ # Configure sensitive parameters which will be filtered from the log file.
36
+ config.filter_parameters += [:password]
37
+
38
+ # Use SQL instead of Active Record's schema dumper when creating the database.
39
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
40
+ # like if you have constraints or database-specific column types
41
+ # config.active_record.schema_format = :sql
42
+
43
+ # Enforce whitelist mode for mass assignment.
44
+ # This will create an empty whitelist of attributes available for mass-assignment for all models
45
+ # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
46
+ # parameters by using an attr_accessible or attr_protected declaration.
47
+ config.active_record.whitelist_attributes = true
48
+
49
+ # Enable the asset pipeline
50
+ config.assets.enabled = true
51
+
52
+ # Version of your assets, change this if you want to expire all your assets
53
+ config.assets.version = '1.0'
54
+ end
55
+ end
56
+
57
+ require 'enju_leaf'
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ gemfile = File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ if File.exist?(gemfile)
5
+ ENV['BUNDLE_GEMFILE'] = gemfile
6
+ require 'bundler'
7
+ Bundler.setup
8
+ end
9
+
10
+ $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,4 @@
1
+ # Override your default settings for the Cucumber environment here.
2
+
3
+ # By default load in the settings from the test environment:
4
+ require File.join(File.dirname(__FILE__), 'test')
@@ -0,0 +1,28 @@
1
+ # Put all your default configatron settings here.
2
+
3
+ # Example:
4
+ # configatron.emails.welcome.subject = 'Welcome!'
5
+ # configatron.emails.sales_reciept.subject = 'Thanks for your order'
6
+ #
7
+ # configatron.file.storage = :s3
8
+
9
+ configatron.enju.web_hostname = 'localhost'
10
+ configatron.enju.web_port_number = 3000
11
+
12
+ # パトロンの名前を入力する際、姓を先に表示する
13
+ configatron.family_name_first = true
14
+
15
+ configatron.max_number_of_results = 500
16
+ configatron.write_search_log_to_file = true
17
+ configatron.csv_charset_conversion = true
18
+
19
+ # Choose a locale from 'ca', 'de', 'fr', 'jp', 'uk', 'us'
20
+ #AMAZON_AWS_HOSTNAME = 'ecs.amazonaws.com'
21
+ configatron.amazon.aws_hostname = 'ecs.amazonaws.jp'
22
+ configatron.amazon.hostname = 'www.amazon.co.jp'
23
+
24
+ # :google, :amazon
25
+ configatron.book_jacket.source = :google
26
+
27
+ # :mozshot, :simpleapi, :heartrails, :thumbalizr
28
+ configatron.screenshot.generator = :mozshot
@@ -0,0 +1,4 @@
1
+ # Override your default settings for the Development environment here.
2
+ #
3
+ # Example:
4
+ # configatron.file.storage = :local