active-fedora 4.0.0.rc8 → 4.0.0.rc9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +1 -1
- data/History.txt +3 -2
- data/lib/active_fedora.rb +25 -207
- data/lib/active_fedora/config.rb +4 -6
- data/lib/active_fedora/datastream.rb +0 -4
- data/lib/active_fedora/file_configurator.rb +217 -0
- data/lib/active_fedora/predicates.rb +2 -2
- data/lib/active_fedora/rdf_datastream.rb +11 -6
- data/lib/active_fedora/solr_service.rb +5 -1
- data/lib/active_fedora/version.rb +1 -1
- data/spec/config_helper.rb +26 -0
- data/spec/integration/ntriples_datastream_spec.rb +52 -0
- data/spec/spec_helper.rb +4 -1
- data/spec/unit/active_fedora_spec.rb +5 -308
- data/spec/unit/code_configurator_spec.rb +51 -0
- data/spec/unit/config_spec.rb +4 -4
- data/spec/unit/file_configurator_spec.rb +273 -0
- data/spec/unit/solr_service_spec.rb +0 -1
- metadata +11 -6
- data/spec/unit/datastream_concurrency_spec.rb +0 -59
data/Gemfile.lock
CHANGED
data/History.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
4.0.0.
|
1
|
+
4.0.0.rc9
|
2
2
|
Removed deprecations
|
3
3
|
* allowing :fedora level in fedora.yml
|
4
4
|
* automatic includes of Relationships and FileMethods is removed
|
@@ -8,11 +8,12 @@ Improved loading from solr
|
|
8
8
|
RDF datastreams
|
9
9
|
Replaced solr-ruby with rsolr. Note: remove any calls to .hits
|
10
10
|
load_instance is now deprecated, replaced with find
|
11
|
-
Find
|
11
|
+
Find always casts to the appropriate object.
|
12
12
|
Run a stub :environment task in the fixture loading rake tasks (which is overridden by rails)
|
13
13
|
Find raises ObjectNotFoundError when the object isn't found
|
14
14
|
Removed dependency on solrizer-fedora
|
15
15
|
Avoid unnecessary reload of RELS-EXT when typecasting
|
16
|
+
HYDRA-754 Delegate discovery of config parameters to a separate module to allow for non-file-based configuration
|
16
17
|
|
17
18
|
3.3.2
|
18
19
|
HYDRA-745 No need to require :url be present on external datastreams
|
data/lib/active_fedora.rb
CHANGED
@@ -27,6 +27,7 @@ module ActiveFedora #:nodoc:
|
|
27
27
|
autoload :ContentModel
|
28
28
|
autoload :Callbacks
|
29
29
|
autoload :Config
|
30
|
+
autoload :FileConfigurator
|
30
31
|
autoload :Reflection
|
31
32
|
autoload :Relationships
|
32
33
|
autoload :FileManagement
|
@@ -56,164 +57,40 @@ module ActiveFedora #:nodoc:
|
|
56
57
|
autoload :NamedRelationships
|
57
58
|
autoload :Predicates
|
58
59
|
autoload :Validations
|
59
|
-
|
60
60
|
end
|
61
61
|
|
62
62
|
|
63
63
|
include Loggable
|
64
64
|
|
65
65
|
class << self
|
66
|
-
|
67
|
-
|
66
|
+
attr_reader :fedora_config, :solr_config, :config_options
|
67
|
+
attr_accessor :configurator
|
68
68
|
end
|
69
|
+
self.configurator ||= ActiveFedora::FileConfigurator.new
|
70
|
+
|
71
|
+
def self.fedora_config
|
72
|
+
@fedora_config ||= Config.new(configurator.fedora_config)
|
73
|
+
end
|
74
|
+
def self.solr_config; self.configurator.solr_config; end
|
75
|
+
def self.config_options; self.configurator.config_options; end
|
76
|
+
def self.config_loaded?; self.configurator.config_loaded?; end
|
69
77
|
|
70
|
-
# The configuration hash that gets used by RSolr.connect
|
71
|
-
@solr_config ||= {}
|
72
|
-
@fedora_config ||= {}
|
73
|
-
@config_options ||= {}
|
74
|
-
|
75
|
-
# Initializes ActiveFedora's connection to Fedora and Solr based on the info in fedora.yml and solr.yml
|
76
|
-
# NOTE: this deprecates the use of a solr url in the fedora.yml
|
77
|
-
#
|
78
|
-
#
|
79
|
-
# If Rails.env is set, it will use that environment. Defaults to "development".
|
80
|
-
# @param [Hash] options (optional) a list of options for the configuration of active_fedora
|
81
|
-
# @option options [String] :environment The environment within which to run
|
82
|
-
# @option options [String] :fedora_config_path The full path to the fedora.yml config file.
|
83
|
-
# @option options [String] :solr_config_path The full path to the solr.yml config file.
|
84
|
-
#
|
85
|
-
# If :environment is not set, order of preference is
|
86
|
-
# 1. Rails.env
|
87
|
-
# 2. ENV['environment']
|
88
|
-
# 3. RAILS_ENV
|
89
|
-
#
|
90
|
-
# If :fedora_config_path is not set, it will look in
|
91
|
-
# 1. +Rails.root+/config
|
92
|
-
# 2. +current working directory+/config
|
93
|
-
# 3. (default) the fedora.yml shipped with gem
|
94
|
-
#
|
95
|
-
# If :solr_config_path is not set, it will
|
96
|
-
# 1. look in config_options[:fedora_config_path]. If it finds a solr.yml there, it will use it.
|
97
|
-
# 2. If it does not find a solr.yml and the fedora.yml contains a solr url, it will raise an configuration error
|
98
|
-
# 3. If it does not find a solr.yml and the fedora.yml does not contain a solr url, it will look in: +Rails.root+/config, +current working directory+/config, then the solr.yml shipped with gem
|
99
|
-
|
100
|
-
# Options allowed in fedora.yml
|
101
|
-
# first level is the environment (e.g. development, test, production and any custom environments you may have)
|
102
|
-
# the second level has these keys:
|
103
|
-
# 1. url: url including protocol, host, port and path (e.g. http://127.0.0.1:8983/fedora)
|
104
|
-
# 2. user: username
|
105
|
-
# 3. password: password
|
106
|
-
# 4. validateChecksum: indicates to the fedora server whether you want to validate checksums when the datastreams are queried.
|
107
|
-
#
|
108
|
-
# @example If you want to shard the fedora instance, you can specify an array of credentials.
|
109
|
-
# production:
|
110
|
-
# - user: user1
|
111
|
-
# password: password1
|
112
|
-
# url: http://127.0.0.1:8983/fedora1
|
113
|
-
# - user: user2
|
114
|
-
# password: password2
|
115
|
-
# url: http://127.0.0.1:8983/fedora2
|
116
|
-
#
|
117
|
-
|
118
78
|
def self.init( options={} )
|
119
79
|
# Make config_options into a Hash if nil is passed in as the value
|
120
80
|
options = {} if options.nil?
|
121
|
-
|
122
81
|
# For backwards compatibility, handle cases where config_path (a String) is passed in as the argument rather than a config_options hash
|
123
82
|
# In all other cases, set config_path to config_options[:config_path], which is ok if it's nil
|
124
83
|
if options.is_a? String
|
125
84
|
raise ArgumentError, "Calling ActiveFedora.init with a path as an argument has been removed. Use ActiveFedora.init(:fedora_config_path=>#{options})"
|
126
|
-
else
|
127
|
-
@config_options = options
|
128
85
|
end
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
reset!
|
134
|
-
load_configs
|
86
|
+
@fedora_config = nil
|
87
|
+
SolrService.reset!
|
88
|
+
Predicates.predicate_config = nil
|
89
|
+
self.configurator.init(options)
|
135
90
|
end
|
136
91
|
|
137
92
|
def self.config
|
138
|
-
|
139
|
-
@fedora_config
|
140
|
-
end
|
141
|
-
|
142
|
-
def self.reset!
|
143
|
-
@config_loaded = false #Force reload of configs
|
144
|
-
@predicate_config_path = nil
|
145
|
-
end
|
146
|
-
|
147
|
-
def self.config_loaded?
|
148
|
-
@config_loaded || false
|
149
|
-
end
|
150
|
-
|
151
|
-
def self.load_configs
|
152
|
-
return if config_loaded?
|
153
|
-
@config_env = environment
|
154
|
-
@fedora_config = Config.new(get_config_path(:fedora), @config_env)
|
155
|
-
load_config(:solr)
|
156
|
-
@config_loaded = true
|
157
|
-
|
158
|
-
end
|
159
|
-
|
160
|
-
def self.load_config(config_type)
|
161
|
-
config_path = get_config_path(config_type)
|
162
|
-
config_type = config_type.to_s
|
163
|
-
self.instance_variable_set "@#{config_type}_config_path".to_sym, config_path
|
164
|
-
config_path = self.send("#{config_type}_config_path".to_sym)
|
165
|
-
|
166
|
-
logger.info("#{config_type.upcase}: loading ActiveFedora.#{config_type}_config from #{File.expand_path(config_path)}")
|
167
|
-
config = YAML.load(File.open(config_path)).symbolize_keys
|
168
|
-
raise "The #{@config_env.to_sym} environment settings were not found in the #{config_type}.yml config. If you already have a #{config_type}.yml file defined, make sure it defines settings for the #{@config_env} environment" unless config[@config_env.to_sym]
|
169
|
-
|
170
|
-
config[:url] = determine_url(config_type,config)
|
171
|
-
|
172
|
-
self.instance_variable_set("@#{config_type}_config", config)
|
173
|
-
config
|
174
|
-
end
|
175
|
-
|
176
|
-
def self.config_for_environment
|
177
|
-
ActiveSupport::Deprecation.warn("config_for_environment has been deprecated use `config' instead")
|
178
|
-
config
|
179
|
-
end
|
180
|
-
|
181
|
-
# Determines and sets the fedora_config[:url] or solr_config[:url]
|
182
|
-
# @param [String] config_type Either 'fedora' or 'solr'
|
183
|
-
# @param [Hash] config The config hash
|
184
|
-
# @return [String] the solr or fedora url
|
185
|
-
def self.determine_url(config_type,config)
|
186
|
-
c = config[environment.to_sym]
|
187
|
-
c.symbolize_keys!
|
188
|
-
if config_type == "fedora"
|
189
|
-
url = c[:url]
|
190
|
-
if url && !c[:user]
|
191
|
-
u = URI.parse url
|
192
|
-
c[:user] = u.user
|
193
|
-
c[:password] = u.password
|
194
|
-
c[:url] = "#{u.scheme}://#{u.host}:#{u.port}#{u.path}"
|
195
|
-
url = c[:url]
|
196
|
-
end
|
197
|
-
return url
|
198
|
-
else
|
199
|
-
return get_solr_url(c) if config_type == "solr"
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
# Given the solr_config that's been loaded for this environment,
|
204
|
-
# determine which solr url to use
|
205
|
-
def self.get_solr_url(solr_config)
|
206
|
-
if @index_full_text == true && solr_config.has_key?(:fulltext) && solr_config[:fulltext].has_key?('url')
|
207
|
-
return solr_config[:fulltext]['url']
|
208
|
-
elsif solr_config.has_key?(:default) && solr_config[:default].has_key?('url')
|
209
|
-
return solr_config[:default]['url']
|
210
|
-
elsif solr_config.has_key?('url')
|
211
|
-
return solr_config['url']
|
212
|
-
elsif solr_config.has_key?(:url)
|
213
|
-
return solr_config[:url]
|
214
|
-
else
|
215
|
-
raise URI::InvalidURIError
|
216
|
-
end
|
93
|
+
self.fedora_config
|
217
94
|
end
|
218
95
|
|
219
96
|
# Determine what environment we're running in. Order of preference is:
|
@@ -242,56 +119,15 @@ module ActiveFedora #:nodoc:
|
|
242
119
|
end
|
243
120
|
end
|
244
121
|
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
# 3. Look in +current working directory+/config/fedora.yml
|
249
|
-
# 4. Load the default config that ships with this gem
|
250
|
-
# @param [String] config_type Either ‘fedora’ or ‘solr’
|
251
|
-
# @return [String]
|
252
|
-
def self.get_config_path(config_type)
|
253
|
-
config_type = config_type.to_s
|
254
|
-
if (config_path = config_options.fetch("#{config_type}_config_path".to_sym,nil) )
|
255
|
-
raise ConfigurationError, "file does not exist #{config_path}" unless File.file? config_path
|
256
|
-
return File.expand_path(config_path)
|
257
|
-
end
|
258
|
-
|
259
|
-
# if solr, attempt to use path where fedora.yml is first
|
260
|
-
if config_type == "solr" && (config_path = check_fedora_path_for_solr)
|
261
|
-
return config_path
|
262
|
-
end
|
263
|
-
|
264
|
-
if defined?(Rails.root)
|
265
|
-
config_path = "#{Rails.root}/config/#{config_type}.yml"
|
266
|
-
return config_path if File.file? config_path
|
267
|
-
end
|
268
|
-
|
269
|
-
if File.file? "#{Dir.getwd}/config/#{config_type}.yml"
|
270
|
-
return "#{Dir.getwd}/config/#{config_type}.yml"
|
271
|
-
end
|
272
|
-
|
273
|
-
# Last choice, check for the default config file
|
274
|
-
config_path = File.expand_path(File.join(File.dirname(__FILE__), "..", "config", "#{config_type}.yml"))
|
275
|
-
logger.warn "Using the default #{config_type}.yml that comes with active-fedora. If you want to override this, pass the path to #{config_type}.yml to ActiveFedora - ie. ActiveFedora.init(:#{config_type}_config_path => '/path/to/#{config_type}.yml) - or set Rails.root and put #{config_type}.yml into \#{Rails.root}/config."
|
276
|
-
return config_path if File.file? config_path
|
277
|
-
raise ConfigurationError "Couldn't load #{config_type} config file!"
|
278
|
-
end
|
279
|
-
|
280
|
-
# Checks the existing fedora_config.path to see if there is a solr.yml there
|
281
|
-
def self.check_fedora_path_for_solr
|
282
|
-
path = @fedora_config.path.split('/')[0..-2].join('/') + "/solr.yml"
|
283
|
-
if File.file? path
|
284
|
-
return path
|
285
|
-
else
|
286
|
-
return nil
|
287
|
-
end
|
122
|
+
def self.config_for_environment
|
123
|
+
ActiveSupport::Deprecation.warn("config_for_environment has been deprecated use `config' instead")
|
124
|
+
config
|
288
125
|
end
|
289
126
|
|
290
127
|
def self.solr
|
291
128
|
ActiveFedora::SolrService.instance
|
292
129
|
end
|
293
130
|
|
294
|
-
|
295
131
|
def self.fedora
|
296
132
|
ActiveSupport::Deprecation.warn("ActiveFedora.fedora() is deprecated and will be removed in the next release use ActiveFedora::Base.connection_for_pid(pid) instead")
|
297
133
|
|
@@ -299,35 +135,17 @@ module ActiveFedora #:nodoc:
|
|
299
135
|
end
|
300
136
|
|
301
137
|
def self.predicate_config
|
302
|
-
|
138
|
+
configurator.predicate_config
|
303
139
|
end
|
304
|
-
|
140
|
+
|
141
|
+
def self.root
|
142
|
+
File.expand_path('../..', __FILE__)
|
143
|
+
end
|
144
|
+
|
305
145
|
def self.version
|
306
146
|
ActiveFedora::VERSION
|
307
147
|
end
|
308
148
|
|
309
|
-
protected
|
310
|
-
|
311
|
-
def self.build_predicate_config_path(config_path=nil)
|
312
|
-
pred_config_paths = [File.expand_path(File.join(File.dirname(__FILE__),"..","config"))]
|
313
|
-
pred_config_paths.unshift config_path if config_path
|
314
|
-
pred_config_paths.each do |path|
|
315
|
-
testfile = File.expand_path(File.join(path,"predicate_mappings.yml"))
|
316
|
-
if File.exist?(testfile) && valid_predicate_mapping?(testfile)
|
317
|
-
return testfile
|
318
|
-
end
|
319
|
-
end
|
320
|
-
raise PredicateMappingsNotFoundError #"Could not find predicate_mappings.yml in these locations: #{pred_config_paths.join("; ")}." unless @predicate_config_path
|
321
|
-
end
|
322
|
-
|
323
|
-
def self.valid_predicate_mapping?(testfile)
|
324
|
-
mapping = YAML::load(File.open(testfile))
|
325
|
-
return false unless mapping.has_key?(:default_namespace) && mapping[:default_namespace].is_a?(String)
|
326
|
-
return false unless mapping.has_key?(:predicate_mapping) && mapping[:predicate_mapping].is_a?(Hash)
|
327
|
-
true
|
328
|
-
end
|
329
|
-
|
330
|
-
|
331
149
|
end
|
332
150
|
|
333
151
|
|
data/lib/active_fedora/config.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
module ActiveFedora
|
2
2
|
class Config
|
3
|
-
attr_reader :
|
4
|
-
def initialize(
|
5
|
-
@path = config_path
|
6
|
-
val = YAML.load(File.open(config_path))[env]
|
3
|
+
attr_reader :credentials
|
4
|
+
def initialize(val)
|
7
5
|
if val.is_a? Array
|
8
6
|
init_shards(val)
|
9
7
|
else
|
@@ -24,14 +22,14 @@ module ActiveFedora
|
|
24
22
|
def init_single(vals)
|
25
23
|
@credentials = vals.symbolize_keys
|
26
24
|
if @credentials[:url] && !@credentials[:user]
|
27
|
-
ActiveSupport::Deprecation.warn("
|
25
|
+
ActiveSupport::Deprecation.warn("Configuring fedora with \":url\" without :user and :password is no longer supported.")
|
28
26
|
u = URI.parse @credentials[:url]
|
29
27
|
@credentials[:user] = u.user
|
30
28
|
@credentials[:password] = u.password
|
31
29
|
@credentials[:url] = "#{u.scheme}://#{u.host}:#{u.port}#{u.path}"
|
32
30
|
end
|
33
31
|
unless @credentials.has_key?(:user) && @credentials.has_key?(:password) && @credentials.has_key?(:url)
|
34
|
-
raise ActiveFedora::ConfigurationError, "
|
32
|
+
raise ActiveFedora::ConfigurationError, "Fedora configuration must provide :user, :password and :url."
|
35
33
|
end
|
36
34
|
end
|
37
35
|
end
|
@@ -0,0 +1,217 @@
|
|
1
|
+
module ActiveFedora
|
2
|
+
class FileConfigurator
|
3
|
+
|
4
|
+
# Initializes ActiveFedora's connection to Fedora and Solr based on the info in fedora.yml and solr.yml
|
5
|
+
# NOTE: this deprecates the use of a solr url in the fedora.yml
|
6
|
+
#
|
7
|
+
#
|
8
|
+
# If Rails.env is set, it will use that environment. Defaults to "development".
|
9
|
+
# @param [Hash] options (optional) a list of options for the configuration of active_fedora
|
10
|
+
# @option options [String] :environment The environment within which to run
|
11
|
+
# @option options [String] :fedora_config_path The full path to the fedora.yml config file.
|
12
|
+
# @option options [String] :solr_config_path The full path to the solr.yml config file.
|
13
|
+
#
|
14
|
+
# If :environment is not set, order of preference is
|
15
|
+
# 1. Rails.env
|
16
|
+
# 2. ENV['environment']
|
17
|
+
# 3. RAILS_ENV
|
18
|
+
#
|
19
|
+
# If :fedora_config_path is not set, it will look in
|
20
|
+
# 1. +Rails.root+/config
|
21
|
+
# 2. +current working directory+/config
|
22
|
+
# 3. (default) the fedora.yml shipped with gem
|
23
|
+
#
|
24
|
+
# If :solr_config_path is not set, it will
|
25
|
+
# 1. look in config_options[:fedora_config_path]. If it finds a solr.yml there, it will use it.
|
26
|
+
# 2. If it does not find a solr.yml and the fedora.yml contains a solr url, it will raise an configuration error
|
27
|
+
# 3. If it does not find a solr.yml and the fedora.yml does not contain a solr url, it will look in: +Rails.root+/config, +current working directory+/config, then the solr.yml shipped with gem
|
28
|
+
|
29
|
+
# Options allowed in fedora.yml
|
30
|
+
# first level is the environment (e.g. development, test, production and any custom environments you may have)
|
31
|
+
# the second level has these keys:
|
32
|
+
# 1. url: url including protocol, host, port and path (e.g. http://127.0.0.1:8983/fedora)
|
33
|
+
# 2. user: username
|
34
|
+
# 3. password: password
|
35
|
+
# 4. validateChecksum: indicates to the fedora server whether you want to validate checksums when the datastreams are queried.
|
36
|
+
#
|
37
|
+
# @example If you want to shard the fedora instance, you can specify an array of credentials.
|
38
|
+
# production:
|
39
|
+
# - user: user1
|
40
|
+
# password: password1
|
41
|
+
# url: http://127.0.0.1:8983/fedora1
|
42
|
+
# - user: user2
|
43
|
+
# password: password2
|
44
|
+
# url: http://127.0.0.1:8983/fedora2
|
45
|
+
#
|
46
|
+
|
47
|
+
attr_accessor :solr_config, :fedora_config, :config_env
|
48
|
+
attr_reader :config_options, :fedora_config_path, :solr_config_path
|
49
|
+
|
50
|
+
# The configuration hash that gets used by RSolr.connect
|
51
|
+
@solr_config ||= {}
|
52
|
+
@fedora_config ||= {}
|
53
|
+
@config_options ||= {}
|
54
|
+
|
55
|
+
def init options = {}
|
56
|
+
if options.is_a?(String)
|
57
|
+
raise ArgumentError, "Calling ActiveFedora.init with a path as an argument has been removed. Use ActiveFedora.init(:fedora_config_path=>#{options})"
|
58
|
+
end
|
59
|
+
@config_options = options
|
60
|
+
config_reload!
|
61
|
+
end
|
62
|
+
|
63
|
+
def config_reload!
|
64
|
+
reset!
|
65
|
+
load_configs
|
66
|
+
end
|
67
|
+
|
68
|
+
def path
|
69
|
+
get_config_path(:fedora)
|
70
|
+
end
|
71
|
+
|
72
|
+
def reset!
|
73
|
+
@config_loaded = false #Force reload of configs
|
74
|
+
@predicate_config_path = nil
|
75
|
+
end
|
76
|
+
|
77
|
+
def config_loaded?
|
78
|
+
@config_loaded || false
|
79
|
+
end
|
80
|
+
|
81
|
+
def load_configs
|
82
|
+
return if config_loaded?
|
83
|
+
@config_env = ActiveFedora.environment
|
84
|
+
|
85
|
+
config_path = get_config_path(:fedora)
|
86
|
+
@fedora_config = YAML.load(File.open(config_path))[@config_env] || {}
|
87
|
+
load_config(:solr)
|
88
|
+
@config_loaded = true
|
89
|
+
end
|
90
|
+
|
91
|
+
def load_config(config_type)
|
92
|
+
config_path = get_config_path(config_type)
|
93
|
+
config_type = config_type.to_s
|
94
|
+
self.instance_variable_set "@#{config_type}_config_path".to_sym, config_path
|
95
|
+
config_path = self.send("#{config_type}_config_path".to_sym)
|
96
|
+
|
97
|
+
logger.info("#{config_type.upcase}: loading ActiveFedora.#{config_type}_config from #{File.expand_path(config_path)}")
|
98
|
+
config = YAML.load(File.open(config_path)).symbolize_keys
|
99
|
+
raise "The #{@config_env.to_sym} environment settings were not found in the #{config_type}.yml config. If you already have a #{config_type}.yml file defined, make sure it defines settings for the #{@config_env} environment" unless config[@config_env.to_sym]
|
100
|
+
|
101
|
+
config[:url] = determine_url(config_type,config)
|
102
|
+
|
103
|
+
self.instance_variable_set("@#{config_type}_config", config)
|
104
|
+
config
|
105
|
+
end
|
106
|
+
|
107
|
+
# Determines and sets the fedora_config[:url] or solr_config[:url]
|
108
|
+
# @param [String] config_type Either 'fedora' or 'solr'
|
109
|
+
# @param [Hash] config The config hash
|
110
|
+
# @return [String] the solr or fedora url
|
111
|
+
def determine_url(config_type,config)
|
112
|
+
c = config[ActiveFedora.environment.to_sym]
|
113
|
+
c.symbolize_keys!
|
114
|
+
if config_type == "fedora"
|
115
|
+
url = c[:url]
|
116
|
+
if url && !c[:user]
|
117
|
+
u = URI.parse url
|
118
|
+
c[:user] = u.user
|
119
|
+
c[:password] = u.password
|
120
|
+
c[:url] = "#{u.scheme}://#{u.host}:#{u.port}#{u.path}"
|
121
|
+
url = c[:url]
|
122
|
+
end
|
123
|
+
return url
|
124
|
+
else
|
125
|
+
return get_solr_url(c) if config_type == "solr"
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
# Given the solr_config that's been loaded for this environment,
|
130
|
+
# determine which solr url to use
|
131
|
+
def get_solr_url(solr_config)
|
132
|
+
if @index_full_text == true && solr_config.has_key?(:fulltext) && solr_config[:fulltext].has_key?('url')
|
133
|
+
return solr_config[:fulltext]['url']
|
134
|
+
elsif solr_config.has_key?(:default) && solr_config[:default].has_key?('url')
|
135
|
+
return solr_config[:default]['url']
|
136
|
+
elsif solr_config.has_key?('url')
|
137
|
+
return solr_config['url']
|
138
|
+
elsif solr_config.has_key?(:url)
|
139
|
+
return solr_config[:url]
|
140
|
+
else
|
141
|
+
raise URI::InvalidURIError
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
# Determine the fedora config file to use. Order of preference is:
|
146
|
+
# 1. Use the config_options[:config_path] if it exists
|
147
|
+
# 2. Look in +Rails.root+/config/fedora.yml
|
148
|
+
# 3. Look in +current working directory+/config/fedora.yml
|
149
|
+
# 4. Load the default config that ships with this gem
|
150
|
+
# @param [String] config_type Either ‘fedora’ or ‘solr’
|
151
|
+
# @return [String]
|
152
|
+
def get_config_path(config_type)
|
153
|
+
config_type = config_type.to_s
|
154
|
+
if (config_path = config_options.fetch("#{config_type}_config_path".to_sym,nil) )
|
155
|
+
raise ConfigurationError, "file does not exist #{config_path}" unless File.file? config_path
|
156
|
+
return File.expand_path(config_path)
|
157
|
+
end
|
158
|
+
|
159
|
+
# if solr, attempt to use path where fedora.yml is first
|
160
|
+
if config_type == "solr" && (config_path = check_fedora_path_for_solr)
|
161
|
+
return config_path
|
162
|
+
end
|
163
|
+
|
164
|
+
if defined?(Rails.root)
|
165
|
+
config_path = "#{Rails.root}/config/#{config_type}.yml"
|
166
|
+
return config_path if File.file? config_path
|
167
|
+
end
|
168
|
+
|
169
|
+
if File.file? "#{Dir.getwd}/config/#{config_type}.yml"
|
170
|
+
return "#{Dir.getwd}/config/#{config_type}.yml"
|
171
|
+
end
|
172
|
+
|
173
|
+
# Last choice, check for the default config file
|
174
|
+
config_path = File.join(ActiveFedora.root, "config", "#{config_type}.yml")
|
175
|
+
logger.warn "Using the default #{config_type}.yml that comes with active-fedora. If you want to override this, pass the path to #{config_type}.yml to ActiveFedora - ie. ActiveFedora.init(:#{config_type}_config_path => '/path/to/#{config_type}.yml') - or set Rails.root and put #{config_type}.yml into \#{Rails.root}/config."
|
176
|
+
return config_path if File.file? config_path
|
177
|
+
raise ConfigurationError "Couldn't load #{config_type} config file!"
|
178
|
+
end
|
179
|
+
|
180
|
+
# Checks the existing fedora_config.path to see if there is a solr.yml there
|
181
|
+
def check_fedora_path_for_solr
|
182
|
+
path = File.dirname(self.path) + "/solr.yml"
|
183
|
+
if File.file? path
|
184
|
+
return path
|
185
|
+
else
|
186
|
+
return nil
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
def predicate_config
|
191
|
+
@predicate_config_path ||= build_predicate_config_path(File.dirname(self.path))
|
192
|
+
YAML::load(File.open(@predicate_config_path)) if File.exist?(@predicate_config_path)
|
193
|
+
end
|
194
|
+
|
195
|
+
protected
|
196
|
+
|
197
|
+
def build_predicate_config_path(config_path=nil)
|
198
|
+
pred_config_paths = [File.join(ActiveFedora.root,"config")]
|
199
|
+
pred_config_paths.unshift config_path if config_path
|
200
|
+
pred_config_paths.each do |path|
|
201
|
+
testfile = File.expand_path(File.join(path,"predicate_mappings.yml"))
|
202
|
+
if File.exist?(testfile) && valid_predicate_mapping?(testfile)
|
203
|
+
return testfile
|
204
|
+
end
|
205
|
+
end
|
206
|
+
raise PredicateMappingsNotFoundError #"Could not find predicate_mappings.yml in these locations: #{pred_config_paths.join("; ")}." unless @predicate_config_path
|
207
|
+
end
|
208
|
+
|
209
|
+
def valid_predicate_mapping?(testfile)
|
210
|
+
mapping = YAML::load(File.open(testfile))
|
211
|
+
return false unless mapping.has_key?(:default_namespace) && mapping[:default_namespace].is_a?(String)
|
212
|
+
return false unless mapping.has_key?(:predicate_mapping) && mapping[:predicate_mapping].is_a?(Hash)
|
213
|
+
true
|
214
|
+
end
|
215
|
+
|
216
|
+
end
|
217
|
+
end
|