active-fedora 11.0.0 → 12.0.0
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +12 -2
- data/.rubocop_todo.yml +73 -18
- data/.travis.yml +8 -9
- data/CONTRIBUTING.md +66 -20
- data/History.txt +51 -0
- data/README.md +11 -14
- data/active-fedora.gemspec +14 -13
- data/lib/active_fedora/aggregation/base_extension.rb +3 -1
- data/lib/active_fedora/aggregation/list_source.rb +1 -1
- data/lib/active_fedora/associations/association.rb +1 -2
- data/lib/active_fedora/associations/basic_contains_association.rb +12 -0
- data/lib/active_fedora/associations/builder/association.rb +1 -2
- data/lib/active_fedora/associations/collection_association.rb +3 -3
- data/lib/active_fedora/associations/collection_proxy.rb +10 -10
- data/lib/active_fedora/associations/contained_finder.rb +2 -1
- data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +1 -1
- data/lib/active_fedora/associations/null_validator.rb +1 -2
- data/lib/active_fedora/associations/rdf.rb +1 -1
- data/lib/active_fedora/attached_files.rb +4 -0
- data/lib/active_fedora/attribute_methods.rb +1 -1
- data/lib/active_fedora/attributes/property_builder.rb +7 -5
- data/lib/active_fedora/caching_connection.rb +1 -1
- data/lib/active_fedora/cleaner.rb +1 -1
- data/lib/active_fedora/common.rb +10 -0
- data/lib/active_fedora/containers/container.rb +1 -2
- data/lib/active_fedora/core.rb +12 -5
- data/lib/active_fedora/errors.rb +4 -0
- data/lib/active_fedora/fedora.rb +19 -5
- data/lib/active_fedora/file/attributes.rb +5 -0
- data/lib/active_fedora/file.rb +3 -3
- data/lib/active_fedora/file_configurator.rb +5 -5
- data/lib/active_fedora/file_io.rb +120 -0
- data/lib/active_fedora/fixity_service.rb +36 -5
- data/lib/active_fedora/indexers/null_indexer.rb +1 -2
- data/lib/active_fedora/indexing/default_descriptors.rb +128 -0
- data/lib/active_fedora/indexing/descendant_fetcher.rb +105 -0
- data/lib/active_fedora/indexing/descriptor.rb +44 -0
- data/lib/active_fedora/indexing/field_mapper.rb +146 -0
- data/lib/active_fedora/indexing/inserter.rb +40 -0
- data/lib/active_fedora/indexing/map.rb +11 -3
- data/lib/active_fedora/indexing/suffix.rb +81 -0
- data/lib/active_fedora/indexing.rb +39 -15
- data/lib/active_fedora/indexing_service.rb +8 -3
- data/lib/active_fedora/inheritance.rb +1 -1
- data/lib/active_fedora/initializing_connection.rb +1 -1
- data/lib/active_fedora/ldp_resource.rb +1 -2
- data/lib/active_fedora/model_classifier.rb +1 -1
- data/lib/active_fedora/null_logger.rb +13 -0
- data/lib/active_fedora/orders/ordered_list.rb +1 -1
- data/lib/active_fedora/persistence.rb +16 -3
- data/lib/active_fedora/property.rb +1 -2
- data/lib/active_fedora/railtie.rb +6 -2
- data/lib/active_fedora/rake_support.rb +1 -1
- data/lib/active_fedora/rdf/field_map.rb +2 -2
- data/lib/active_fedora/rdf/field_map_entry.rb +15 -7
- data/lib/active_fedora/rdf/indexing_service.rb +15 -13
- data/lib/active_fedora/rdf/value_caster.rb +15 -0
- data/lib/active_fedora/rdf.rb +1 -0
- data/lib/active_fedora/relation/finder_methods.rb +28 -40
- data/lib/active_fedora/solr_hit.rb +1 -1
- data/lib/active_fedora/solr_service.rb +20 -2
- data/lib/active_fedora/type/value.rb +2 -4
- data/lib/active_fedora/version.rb +1 -1
- data/lib/active_fedora/with_metadata/metadata_node.rb +4 -1
- data/lib/active_fedora.rb +23 -9
- data/lib/generators/active_fedora/config/fedora/templates/.fcrepo_wrapper +1 -1
- data/lib/generators/active_fedora/config/solr/templates/solr/config/schema.xml +0 -6
- data/lib/generators/active_fedora/config/solr/templates/solr.yml +3 -3
- data/spec/integration/associations_spec.rb +8 -8
- data/spec/integration/attached_files_spec.rb +2 -3
- data/spec/integration/base_spec.rb +43 -39
- data/spec/integration/basic_contains_association_spec.rb +16 -3
- data/spec/integration/collection_association_spec.rb +1 -1
- data/spec/integration/direct_container_spec.rb +2 -2
- data/spec/integration/fedora_solr_sync_spec.rb +1 -1
- data/spec/integration/file_spec.rb +46 -13
- data/spec/integration/generators/fedora_generator_spec.rb +1 -1
- data/spec/integration/generators/solr_generator_spec.rb +1 -1
- data/spec/integration/has_and_belongs_to_many_associations_spec.rb +2 -2
- data/spec/integration/has_many_associations_spec.rb +4 -5
- data/spec/integration/indexing/descendant_fetcher_spec.rb +64 -0
- data/spec/integration/indexing_spec.rb +22 -2
- data/spec/integration/indirect_container_spec.rb +2 -2
- data/spec/integration/query_result_builder_spec.rb +2 -2
- data/spec/integration/scoping_spec.rb +20 -14
- data/spec/integration/solr_hit_spec.rb +1 -1
- data/spec/integration/versionable_spec.rb +2 -2
- data/spec/lib/active_fedora/null_logger_spec.rb +10 -0
- data/spec/unit/active_fedora/indexing/inserter_spec.rb +30 -0
- data/spec/unit/attached_files_spec.rb +36 -8
- data/spec/unit/attributes_spec.rb +8 -14
- data/spec/unit/base_spec.rb +7 -7
- data/spec/unit/builder/has_and_belongs_to_many_spec.rb +1 -1
- data/spec/unit/callback_spec.rb +2 -2
- data/spec/unit/change_set_spec.rb +1 -2
- data/spec/unit/collection_proxy_spec.rb +2 -1
- data/spec/unit/core/fedora_id_translator_spec.rb +2 -2
- data/spec/unit/core/fedora_uri_translator_spec.rb +2 -2
- data/spec/unit/core/logger_spec.rb +18 -0
- data/spec/unit/core_spec.rb +46 -12
- data/spec/unit/default_model_mapper_spec.rb +1 -1
- data/spec/unit/fedora_spec.rb +12 -0
- data/spec/unit/file_configurator_spec.rb +0 -9
- data/spec/unit/file_io_spec.rb +137 -0
- data/spec/unit/file_path_builder_spec.rb +3 -3
- data/spec/unit/file_spec.rb +70 -26
- data/spec/unit/files_hash_spec.rb +1 -2
- data/spec/unit/filter_spec.rb +2 -2
- data/spec/unit/finder_methods_spec.rb +1 -1
- data/spec/unit/fixity_service_spec.rb +65 -5
- data/spec/unit/has_and_belongs_to_many_association_spec.rb +1 -2
- data/spec/unit/has_many_association_spec.rb +2 -2
- data/spec/unit/indexing/map/index_object_spec.rb +25 -0
- data/spec/unit/indexing/map_spec.rb +27 -0
- data/spec/unit/indexing_spec.rb +3 -4
- data/spec/unit/inheritance_spec.rb +28 -1
- data/spec/unit/model_classifier_spec.rb +1 -1
- data/spec/unit/pathing_spec.rb +1 -2
- data/spec/unit/query_result_builder_spec.rb +1 -2
- data/spec/unit/query_spec.rb +4 -4
- data/spec/unit/rdf/indexing_service_spec.rb +18 -4
- data/spec/unit/reflection_spec.rb +2 -2
- data/spec/unit/solr_hit_spec.rb +1 -2
- data/spec/unit/solr_service_spec.rb +52 -4
- data/spec/unit/sparql_insert_spec.rb +1 -1
- data/spec/unit/validations_spec.rb +27 -4
- data/spec/unit/with_metadata/metadata_node_spec.rb +26 -1
- metadata +99 -29
|
@@ -54,7 +54,7 @@ module ActiveFedora
|
|
|
54
54
|
return if @initialized
|
|
55
55
|
|
|
56
56
|
connection.head(root_resource_path)
|
|
57
|
-
ActiveFedora::Base.logger.info "Attempted to init base path `#{root_resource_path}`, but it already exists"
|
|
57
|
+
ActiveFedora::Base.logger.info "Attempted to init base path `#{root_resource_path}`, but it already exists"
|
|
58
58
|
@initialized = true
|
|
59
59
|
false
|
|
60
60
|
rescue Ldp::NotFound
|
|
@@ -60,7 +60,7 @@ module ActiveFedora
|
|
|
60
60
|
|
|
61
61
|
def classify(model_value)
|
|
62
62
|
unless class_exists?(model_value)
|
|
63
|
-
ActiveFedora::Base.logger.warn "'#{model_value}' is not a real class"
|
|
63
|
+
ActiveFedora::Base.logger.warn "'#{model_value}' is not a real class"
|
|
64
64
|
return nil
|
|
65
65
|
end
|
|
66
66
|
ActiveFedora::ModelClassifier.class_from_string(model_value)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module ActiveFedora
|
|
2
|
+
class NullLogger < Logger
|
|
3
|
+
def initialize(*); end
|
|
4
|
+
|
|
5
|
+
# allows all the usual logger method calls (warn, info, error, etc.)
|
|
6
|
+
def add(*); end
|
|
7
|
+
|
|
8
|
+
# In the NullLogger there are no levels, so none of these should be true.
|
|
9
|
+
[:debug?, :info?, :warn?, :error?, :fatal?].each do |method_name|
|
|
10
|
+
define_method(method_name) { false }
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -174,7 +174,7 @@ module ActiveFedora
|
|
|
174
174
|
def proxy_in
|
|
175
175
|
proxies = to_a.map(&:proxy_in_id).compact.uniq
|
|
176
176
|
if proxies.length > 1
|
|
177
|
-
ActiveFedora::Base.logger.warn "WARNING: List contains nodes aggregated under different URIs. Returning only the first."
|
|
177
|
+
ActiveFedora::Base.logger.warn "WARNING: List contains nodes aggregated under different URIs. Returning only the first."
|
|
178
178
|
end
|
|
179
179
|
proxies.first
|
|
180
180
|
end
|
|
@@ -4,9 +4,13 @@ module ActiveFedora
|
|
|
4
4
|
extend ActiveSupport::Concern
|
|
5
5
|
|
|
6
6
|
def new_record?
|
|
7
|
-
@ldp_source.
|
|
7
|
+
return true if @ldp_source.subject.nil?
|
|
8
|
+
@ldp_source.get
|
|
9
|
+
false
|
|
8
10
|
rescue Ldp::Gone
|
|
9
11
|
false
|
|
12
|
+
rescue Ldp::NotFound
|
|
13
|
+
true
|
|
10
14
|
end
|
|
11
15
|
|
|
12
16
|
def persisted?
|
|
@@ -41,6 +45,15 @@ module ActiveFedora
|
|
|
41
45
|
|
|
42
46
|
alias update_attributes update
|
|
43
47
|
|
|
48
|
+
# Updates its receiver just like #update but calls #save! instead
|
|
49
|
+
# of +save+, so an exception is raised if the record is invalid and saving will fail.
|
|
50
|
+
def update!(attributes)
|
|
51
|
+
assign_attributes(attributes)
|
|
52
|
+
save!
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
alias update_attributes! update!
|
|
56
|
+
|
|
44
57
|
# Deletes an object from Fedora and deletes the indexed record from Solr.
|
|
45
58
|
# Delete does not run any callbacks, so consider using _destroy_ instead.
|
|
46
59
|
# @param [Hash] opts
|
|
@@ -196,8 +209,7 @@ module ActiveFedora
|
|
|
196
209
|
end
|
|
197
210
|
|
|
198
211
|
# Override to tie in an ID minting service
|
|
199
|
-
def assign_id
|
|
200
|
-
end
|
|
212
|
+
def assign_id; end
|
|
201
213
|
|
|
202
214
|
# This is only used when creating a new record. If the object doesn't have an id
|
|
203
215
|
# and assign_id can mint an id for the object, then assign it to the resource.
|
|
@@ -219,6 +231,7 @@ module ActiveFedora
|
|
|
219
231
|
root_resource_path
|
|
220
232
|
end
|
|
221
233
|
|
|
234
|
+
# Check to see if the :base_path (from fedora.yml) exists in Fedora. If it doesn't exist, then create it.
|
|
222
235
|
def init_root_path
|
|
223
236
|
path = root_resource_path.gsub(/^\//, "")
|
|
224
237
|
ActiveFedora.fedora.connection.head(path)
|
|
@@ -2,6 +2,11 @@ module ActiveFedora
|
|
|
2
2
|
class Railtie < Rails::Railtie
|
|
3
3
|
config.app_middleware.insert_after ::ActionDispatch::Callbacks,
|
|
4
4
|
ActiveFedora::LdpCache
|
|
5
|
+
config.action_dispatch.rescue_responses.merge!(
|
|
6
|
+
"ActiveFedora::ObjectNotFoundError" => :not_found
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
config.eager_load_namespaces << ActiveFedora
|
|
5
10
|
|
|
6
11
|
initializer 'active_fedora.autoload', before: :set_autoload_paths do |app|
|
|
7
12
|
app.config.autoload_paths << 'app/models/datastreams'
|
|
@@ -9,8 +14,7 @@ module ActiveFedora
|
|
|
9
14
|
|
|
10
15
|
initializer "active_fedora.logger" do
|
|
11
16
|
ActiveSupport.on_load(:active_fedora) do
|
|
12
|
-
self.logger
|
|
13
|
-
Solrizer.logger ||= logger
|
|
17
|
+
self.logger = ::Rails.logger if logger.is_a? NullLogger
|
|
14
18
|
end
|
|
15
19
|
end
|
|
16
20
|
|
|
@@ -12,7 +12,7 @@ def with_server(environment)
|
|
|
12
12
|
# setting port: nil assigns a random port.
|
|
13
13
|
solr_defaults = { port: nil, verbose: true, managed: true }
|
|
14
14
|
fcrepo_defaults = { port: nil, verbose: true, managed: true,
|
|
15
|
-
enable_jms: false, fcrepo_home_dir: "fcrepo4-#{environment}-data" }
|
|
15
|
+
enable_jms: false, fcrepo_home_dir: "tmp/fcrepo4-#{environment}-data" }
|
|
16
16
|
|
|
17
17
|
SolrWrapper.wrap(load_config(:solr, environment, solr_defaults)) do |solr|
|
|
18
18
|
ENV["SOLR_#{environment.upcase}_PORT"] = solr.port.to_s
|
|
@@ -15,8 +15,8 @@ module ActiveFedora::RDF
|
|
|
15
15
|
|
|
16
16
|
# Inserts each solr field map configuration into the FieldMap class
|
|
17
17
|
# @param [Symbol] name the name of the property on the object that we're indexing
|
|
18
|
-
# @param [
|
|
19
|
-
# @param [
|
|
18
|
+
# @param [ActiveFedora::Indexing::Map::IndexObject] index_field_config describes how the object should be indexed
|
|
19
|
+
# @param [ActiveFedora::Base] object the object to be indexed into Solr
|
|
20
20
|
def insert(name, index_field_config, object)
|
|
21
21
|
self[index_field_config.key.to_s] ||= FieldMapEntry.new
|
|
22
22
|
PolymorphicBuilder.new(self[index_field_config.key.to_s], index_field_config, object, name).build
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
module ActiveFedora::RDF
|
|
2
2
|
# Transient class that represents a field that we send to solr.
|
|
3
3
|
# It might be possible for two properties to share a single field map entry if they use the same solr key.
|
|
4
|
-
# @attribute [Symbol] type the data type hint for
|
|
4
|
+
# @attribute [Symbol] type the data type hint for ActiveFedora::Indexing::FieldMapper
|
|
5
5
|
# @attribute [Array] behaviors the indexing hints such as :stored_searchable or :symbol
|
|
6
|
-
#
|
|
6
|
+
# @!attribute [w] values the raw values
|
|
7
7
|
class FieldMapEntry
|
|
8
|
-
attr_accessor :type, :behaviors
|
|
8
|
+
attr_accessor :type, :behaviors
|
|
9
|
+
attr_writer :values
|
|
9
10
|
|
|
10
11
|
def initialize
|
|
11
12
|
@behaviors = []
|
|
@@ -14,13 +15,20 @@ module ActiveFedora::RDF
|
|
|
14
15
|
|
|
15
16
|
# Merges any existing values for solr fields with new, incoming values and ensures that resulting values are unique.
|
|
16
17
|
# @param [Symbol] type the data type for the field such as :string, :date, :integer
|
|
17
|
-
# @param [Array] behaviors
|
|
18
|
-
# @param [Array] values
|
|
19
|
-
def merge!(type, behaviors,
|
|
18
|
+
# @param [Array] behaviors FieldMapper's behaviors for indexing such as :stored_searchable, :symbol
|
|
19
|
+
# @param [Array] new_values values to append into the existing solr field
|
|
20
|
+
def merge!(type, behaviors, new_values)
|
|
20
21
|
self.type ||= type
|
|
21
22
|
self.behaviors += behaviors
|
|
22
23
|
self.behaviors.uniq!
|
|
23
|
-
self.values +=
|
|
24
|
+
self.values += new_values
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# @return [Array] the actual values that get sent to solr
|
|
28
|
+
def values
|
|
29
|
+
@values.map do |value|
|
|
30
|
+
ValueCaster.new(value).value
|
|
31
|
+
end
|
|
24
32
|
end
|
|
25
33
|
end
|
|
26
34
|
end
|
|
@@ -5,12 +5,17 @@ module ActiveFedora::RDF
|
|
|
5
5
|
# @see ActiveFedora::Indexing
|
|
6
6
|
# @see ActiveFedora::IndexingService
|
|
7
7
|
class IndexingService
|
|
8
|
-
|
|
9
|
-
attr_reader :object
|
|
8
|
+
attr_reader :object, :index_config
|
|
10
9
|
|
|
11
|
-
# @param [#resource, #rdf_subject] obj the object to build an solr document for. Its class must respond to 'properties'
|
|
12
|
-
|
|
10
|
+
# @param [#resource, #rdf_subject] obj the object to build an solr document for. Its class must respond to 'properties'
|
|
11
|
+
# @param [ActiveFedora::Indexing::Map] index_config the configuration to use to map object values to index document values
|
|
12
|
+
def initialize(obj, index_config = nil)
|
|
13
|
+
unless index_config
|
|
14
|
+
Deprecation.warn(self, "initializing ActiveFedora::RDF::IndexingService without an index_config is deprecated and will be removed in ActiveFedora 13.0")
|
|
15
|
+
index_config = obj.class.index_config
|
|
16
|
+
end
|
|
13
17
|
@object = obj
|
|
18
|
+
@index_config = index_config
|
|
14
19
|
end
|
|
15
20
|
|
|
16
21
|
# Creates a solr document hash for the rdf assertions of the {#object}
|
|
@@ -37,13 +42,14 @@ module ActiveFedora::RDF
|
|
|
37
42
|
# Override this in order to allow one field to be expanded into more than one:
|
|
38
43
|
# example:
|
|
39
44
|
# def append_to_solr_doc(solr_doc, field_key, field_info, val)
|
|
40
|
-
#
|
|
41
|
-
#
|
|
45
|
+
# ActiveFedora.index_field_mapper.set_field(solr_doc, 'lcsh_subject_uri', val.to_uri, :symbol)
|
|
46
|
+
# ActiveFedora.index_field_mapper.set_field(solr_doc, 'lcsh_subject_label', val.to_label, :searchable)
|
|
42
47
|
# end
|
|
43
48
|
def append_to_solr_doc(solr_doc, solr_field_key, field_info, val)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
ActiveFedora::Indexing::Inserter.create_and_insert_terms(solr_field_key,
|
|
50
|
+
solr_document_field_value(val),
|
|
51
|
+
field_info.behaviors,
|
|
52
|
+
solr_doc)
|
|
47
53
|
end
|
|
48
54
|
|
|
49
55
|
def solr_document_field_name(field_key, prefix_method)
|
|
@@ -69,10 +75,6 @@ module ActiveFedora::RDF
|
|
|
69
75
|
object.resource
|
|
70
76
|
end
|
|
71
77
|
|
|
72
|
-
def index_config
|
|
73
|
-
object.class.index_config
|
|
74
|
-
end
|
|
75
|
-
|
|
76
78
|
# returns the field map instance
|
|
77
79
|
def fields
|
|
78
80
|
field_map_class.new do |field_map|
|
data/lib/active_fedora/rdf.rb
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
module ActiveFedora
|
|
2
2
|
module FinderMethods
|
|
3
|
-
# Returns the first
|
|
4
|
-
#
|
|
3
|
+
# Returns the first record that was found.
|
|
5
4
|
# @example
|
|
6
5
|
# Person.where(name_t: 'Jones').first
|
|
7
6
|
# => #<Person @id="foo:123" @name='Jones' ... >
|
|
@@ -15,7 +14,6 @@ module ActiveFedora
|
|
|
15
14
|
|
|
16
15
|
# Returns the last record sorted by id. ID was chosen because this mimics
|
|
17
16
|
# how ActiveRecord would achieve the same behavior.
|
|
18
|
-
#
|
|
19
17
|
# @example
|
|
20
18
|
# Person.where(name_t: 'Jones').last
|
|
21
19
|
# => #<Person @id="foo:123" @name='Jones' ... >
|
|
@@ -27,12 +25,10 @@ module ActiveFedora
|
|
|
27
25
|
end
|
|
28
26
|
end
|
|
29
27
|
|
|
30
|
-
#
|
|
31
|
-
# called on
|
|
32
|
-
#
|
|
33
|
-
# @param[String,Hash] args either an id or a hash of conditions
|
|
28
|
+
# @param [String, Hash] args either an id or a hash of conditions
|
|
34
29
|
# @option args [Integer] :rows when :all is passed, the maximum number of rows to load from solr
|
|
35
30
|
# @option args [Boolean] :cast when true, examine the model and cast it to the first known cModel
|
|
31
|
+
# @return [Array] objects of the Class that +find+ is being called on
|
|
36
32
|
def find(*args)
|
|
37
33
|
return to_a.find { |*block_args| yield(*block_args) } if block_given?
|
|
38
34
|
options = args.extract_options!
|
|
@@ -71,10 +67,9 @@ module ActiveFedora
|
|
|
71
67
|
end
|
|
72
68
|
end
|
|
73
69
|
|
|
74
|
-
# Returns true if object having the id or matching the conditions exists in the repository
|
|
75
70
|
# Returns false if param is false (or nil)
|
|
76
|
-
# @param[ActiveFedora::Base, String, Hash] object, id or hash of conditions
|
|
77
|
-
# @return[
|
|
71
|
+
# @param [ActiveFedora::Base, String, Hash] object, id or hash of conditions
|
|
72
|
+
# @return [Boolean] true if object having the id or matching the conditions exists in the repository
|
|
78
73
|
def exists?(conditions)
|
|
79
74
|
conditions = conditions.id if Base === conditions
|
|
80
75
|
return false unless conditions
|
|
@@ -86,15 +81,13 @@ module ActiveFedora
|
|
|
86
81
|
else
|
|
87
82
|
raise ArgumentError, "`conditions' argument must be ActiveFedora::Base, String, or Hash: #{conditions.inspect}"
|
|
88
83
|
end
|
|
89
|
-
rescue ActiveFedora::ObjectNotFoundError, Ldp::Gone
|
|
84
|
+
rescue ActiveFedora::ObjectNotFoundError, ActiveFedora::ModelMismatch, Ldp::Gone
|
|
90
85
|
false
|
|
91
86
|
end
|
|
92
87
|
|
|
93
88
|
# Returns a solr result matching the supplied conditions
|
|
94
|
-
# @param[Hash,String] conditions
|
|
95
|
-
# hash
|
|
96
|
-
# provided, this method will generate conditions based simple equality
|
|
97
|
-
# combined using the boolean AND operator.
|
|
89
|
+
# @param [Hash, String] conditions represention of the query part of an solr statement.
|
|
90
|
+
# If a hash is provided, query will combine based on simple equality using the boolean AND operator.
|
|
98
91
|
# @param [Hash] options
|
|
99
92
|
# @option opts [Array] :sort a list of fields to sort by
|
|
100
93
|
# @option opts [Array] :rows number of rows to return
|
|
@@ -110,11 +103,9 @@ module ActiveFedora
|
|
|
110
103
|
def search_by_id(id, opts = {})
|
|
111
104
|
opts[:rows] = 1
|
|
112
105
|
result = search_with_conditions({ id: id }, opts)
|
|
113
|
-
|
|
114
106
|
if result.empty?
|
|
115
|
-
raise ActiveFedora::ObjectNotFoundError, "Object #{id} not found in solr"
|
|
107
|
+
raise ActiveFedora::ObjectNotFoundError, "Object '#{id}' not found in solr"
|
|
116
108
|
end
|
|
117
|
-
|
|
118
109
|
result.first
|
|
119
110
|
end
|
|
120
111
|
|
|
@@ -129,8 +120,8 @@ module ActiveFedora
|
|
|
129
120
|
group.each do |hit|
|
|
130
121
|
begin
|
|
131
122
|
yield(load_from_fedora(hit[ActiveFedora.id_field], cast))
|
|
132
|
-
rescue Ldp::Gone
|
|
133
|
-
ActiveFedora::Base.logger.error "Although #{hit[ActiveFedora.id_field]} was found in Solr, it doesn't seem to exist in Fedora. The index is out of synch."
|
|
123
|
+
rescue Ldp::Gone, ActiveFedora::ObjectNotFoundError
|
|
124
|
+
ActiveFedora::Base.logger.error "Although #{hit[ActiveFedora.id_field]} was found in Solr, it doesn't seem to exist in Fedora. The index is out of synch."
|
|
134
125
|
end
|
|
135
126
|
end
|
|
136
127
|
end
|
|
@@ -141,14 +132,14 @@ module ActiveFedora
|
|
|
141
132
|
# option; the default is 1000.
|
|
142
133
|
#
|
|
143
134
|
# Returns a solr result matching the supplied conditions
|
|
144
|
-
# @param[Hash] conditions solr conditions to match
|
|
145
|
-
# @param[Hash] options
|
|
135
|
+
# @param [Hash] conditions solr conditions to match
|
|
136
|
+
# @param [Hash] options
|
|
146
137
|
# @option opts [Array] :sort a list of fields to sort by
|
|
147
138
|
# @option opts [Array] :rows number of rows to return
|
|
148
139
|
#
|
|
149
140
|
# @example
|
|
150
141
|
# Person.search_in_batches('age_t'=>'21', {:batch_size=>50}) do |group|
|
|
151
|
-
#
|
|
142
|
+
# group.each { |person| puts person['name_t'] }
|
|
152
143
|
# end
|
|
153
144
|
def search_in_batches(conditions, opts = {})
|
|
154
145
|
opts[:q] = create_query(conditions)
|
|
@@ -169,11 +160,10 @@ module ActiveFedora
|
|
|
169
160
|
end
|
|
170
161
|
end
|
|
171
162
|
|
|
172
|
-
# Retrieve the Fedora object with the given id
|
|
173
|
-
# Raises a ObjectNotFoundError if the object is not found.
|
|
163
|
+
# Retrieve the Fedora object with the given id
|
|
174
164
|
# @param [String] id of the object to load
|
|
175
165
|
# @param [Boolean] cast when true, cast the found object to the class of the first known model defined in it's RELS-EXT
|
|
176
|
-
#
|
|
166
|
+
# @raise [ObjectNotFoundError] if the object is not found
|
|
177
167
|
# @example because the object hydra:dataset1 asserts it is a Dataset (hasModel http://fedora.info/definitions/v4/model#Dataset), return a Dataset object (not a Book).
|
|
178
168
|
# Book.find_one("hydra:dataset1")
|
|
179
169
|
def find_one(id, cast = nil)
|
|
@@ -189,32 +179,28 @@ module ActiveFedora
|
|
|
189
179
|
protected
|
|
190
180
|
|
|
191
181
|
def load_from_fedora(id, cast)
|
|
192
|
-
raise ActiveFedora::ObjectNotFoundError if id.empty?
|
|
182
|
+
raise ActiveFedora::ObjectNotFoundError, "No ID provided for #{klass.name}." if id.empty?
|
|
193
183
|
resource = ActiveFedora.fedora.ldp_resource_service.build(klass, id)
|
|
194
|
-
|
|
184
|
+
raise_record_not_found_exception!(id) if resource.new?
|
|
195
185
|
class_to_load(resource, cast).allocate.init_with_resource(resource) # Triggers the find callback
|
|
196
186
|
end
|
|
197
187
|
|
|
188
|
+
def raise_record_not_found_exception!(id)
|
|
189
|
+
raise ActiveFedora::ObjectNotFoundError, "Couldn't find #{@klass.name} with 'id'=#{id}"
|
|
190
|
+
end
|
|
191
|
+
|
|
198
192
|
def class_to_load(resource, cast)
|
|
199
193
|
if @klass == ActiveFedora::Base && cast == false
|
|
200
194
|
ActiveFedora::Base
|
|
201
195
|
else
|
|
202
|
-
resource_class =
|
|
203
|
-
unless
|
|
204
|
-
raise ActiveFedora::
|
|
196
|
+
resource_class = ActiveFedora.model_mapper.classifier(resource).best_model
|
|
197
|
+
unless resource_class <= @klass
|
|
198
|
+
raise ActiveFedora::ModelMismatch, "Expected #{@klass}. Got: #{resource_class}"
|
|
205
199
|
end
|
|
206
200
|
resource_class
|
|
207
201
|
end
|
|
208
202
|
end
|
|
209
203
|
|
|
210
|
-
def has_model_value(resource)
|
|
211
|
-
ActiveFedora.model_mapper.classifier(resource).best_model
|
|
212
|
-
end
|
|
213
|
-
|
|
214
|
-
def equivalent_class?(other_class)
|
|
215
|
-
other_class <= @klass
|
|
216
|
-
end
|
|
217
|
-
|
|
218
204
|
def find_with_ids(ids, cast)
|
|
219
205
|
expects_array = ids.first.is_a?(Array)
|
|
220
206
|
return ids.first if expects_array && ids.first.empty?
|
|
@@ -239,12 +225,14 @@ module ActiveFedora
|
|
|
239
225
|
private
|
|
240
226
|
|
|
241
227
|
# Returns a solr query for the supplied conditions
|
|
242
|
-
# @param[Hash,String,Array] conditions solr conditions to match
|
|
228
|
+
# @param [Hash, String, Array] conditions solr conditions to match
|
|
229
|
+
# @return [String]
|
|
243
230
|
def create_query(conditions)
|
|
244
231
|
build_query(build_where(conditions))
|
|
245
232
|
end
|
|
246
233
|
|
|
247
234
|
# @param [Array<String>] conditions
|
|
235
|
+
# @return [String]
|
|
248
236
|
def build_query(conditions)
|
|
249
237
|
clauses = search_model_clause ? [search_model_clause] : []
|
|
250
238
|
clauses += conditions.reject(&:blank?)
|
|
@@ -36,7 +36,7 @@ module ActiveFedora
|
|
|
36
36
|
|
|
37
37
|
def model(opts = {})
|
|
38
38
|
best_model_match = classifier.best_model(opts)
|
|
39
|
-
ActiveFedora::Base.logger.warn "Could not find a model for #{id}, defaulting to ActiveFedora::Base" if
|
|
39
|
+
ActiveFedora::Base.logger.warn "Could not find a model for #{id}, defaulting to ActiveFedora::Base" if best_model_match == ActiveFedora::Base
|
|
40
40
|
best_model_match
|
|
41
41
|
end
|
|
42
42
|
|
|
@@ -2,8 +2,11 @@ require 'rsolr'
|
|
|
2
2
|
|
|
3
3
|
module ActiveFedora
|
|
4
4
|
class SolrService
|
|
5
|
+
attr_reader :options
|
|
5
6
|
attr_writer :conn
|
|
6
7
|
|
|
8
|
+
MAX_ROWS = 10_000
|
|
9
|
+
|
|
7
10
|
def initialize(options = {})
|
|
8
11
|
@options = { read_timeout: 120, open_timeout: 120, url: 'http://localhost:8080/solr' }.merge(options)
|
|
9
12
|
end
|
|
@@ -41,8 +44,23 @@ module ActiveFedora
|
|
|
41
44
|
SolrService.instance.conn.get(select_path, params: args)
|
|
42
45
|
end
|
|
43
46
|
|
|
47
|
+
def post(query, args = {})
|
|
48
|
+
args = args.merge(q: query, qt: 'standard')
|
|
49
|
+
SolrService.instance.conn.post(select_path, data: args)
|
|
50
|
+
end
|
|
51
|
+
|
|
44
52
|
def query(query, args = {})
|
|
45
|
-
|
|
53
|
+
Base.logger.warn "Calling ActiveFedora::SolrService.get without passing an explicit value for ':rows' is not recommended. You will end up with Solr's default (usually set to 10)\nCalled by #{caller[0]}" unless args.key?(:rows)
|
|
54
|
+
method = args.delete(:method) || :get
|
|
55
|
+
|
|
56
|
+
result = case method
|
|
57
|
+
when :get
|
|
58
|
+
get(query, args)
|
|
59
|
+
when :post
|
|
60
|
+
post(query, args)
|
|
61
|
+
else
|
|
62
|
+
raise "Unsupported HTTP method for querying SolrService (#{method.inspect})"
|
|
63
|
+
end
|
|
46
64
|
result['response']['docs'].map do |doc|
|
|
47
65
|
ActiveFedora::SolrHit.new(doc)
|
|
48
66
|
end
|
|
@@ -61,7 +79,7 @@ module ActiveFedora
|
|
|
61
79
|
SolrService.get(query, args)['response']['numFound'].to_i
|
|
62
80
|
end
|
|
63
81
|
|
|
64
|
-
# @param [Hash] doc the document to index
|
|
82
|
+
# @param [Hash] doc the document to index, or an array of docs
|
|
65
83
|
# @param [Hash] params
|
|
66
84
|
# :commit => commits immediately
|
|
67
85
|
# :softCommit => commit to memory, but don't flush to disk
|
|
@@ -11,8 +11,7 @@ module ActiveFedora
|
|
|
11
11
|
@limit = limit
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
def type
|
|
15
|
-
end
|
|
14
|
+
def type; end
|
|
16
15
|
|
|
17
16
|
# Converts a value from database input to the appropriate ruby type. The
|
|
18
17
|
# return value of this method will be returned from
|
|
@@ -102,8 +101,7 @@ module ActiveFedora
|
|
|
102
101
|
[self.class, precision, scale, limit].hash
|
|
103
102
|
end
|
|
104
103
|
|
|
105
|
-
def assert_valid_value(*)
|
|
106
|
-
end
|
|
104
|
+
def assert_valid_value(*); end
|
|
107
105
|
|
|
108
106
|
private
|
|
109
107
|
|
|
@@ -10,6 +10,7 @@ module ActiveFedora
|
|
|
10
10
|
# this class rather than being in the DefaultSchema.
|
|
11
11
|
property :mime_type, predicate: ::RDF::Vocab::EBUCore.hasMimeType
|
|
12
12
|
|
|
13
|
+
# @param file [ActiveFedora::File]
|
|
13
14
|
def initialize(file)
|
|
14
15
|
@file = file
|
|
15
16
|
super(file.uri, ldp_source.graph)
|
|
@@ -35,6 +36,7 @@ module ActiveFedora
|
|
|
35
36
|
end
|
|
36
37
|
|
|
37
38
|
def ldp_source
|
|
39
|
+
@ldp_source ||= LdpResource.new(ldp_connection, nil) if file.new_record?
|
|
38
40
|
@ldp_source ||= LdpResource.new(ldp_connection, metadata_uri)
|
|
39
41
|
end
|
|
40
42
|
|
|
@@ -44,8 +46,9 @@ module ActiveFedora
|
|
|
44
46
|
|
|
45
47
|
def save
|
|
46
48
|
raise "Save the file first" if file.new_record?
|
|
47
|
-
SparqlInsert.new(changes_for_update,
|
|
49
|
+
SparqlInsert.new(changes_for_update, file.uri).execute(metadata_uri)
|
|
48
50
|
@ldp_source = nil
|
|
51
|
+
@metadata_uri = nil
|
|
49
52
|
true
|
|
50
53
|
end
|
|
51
54
|
|
data/lib/active_fedora.rb
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
require 'active_support'
|
|
2
2
|
require 'active_model'
|
|
3
3
|
require 'ldp'
|
|
4
|
-
require 'solrizer'
|
|
5
4
|
require 'active_fedora/file_configurator'
|
|
6
5
|
require 'active_support/core_ext/class/attribute'
|
|
7
6
|
require 'active_support/core_ext/object'
|
|
@@ -68,11 +67,11 @@ module ActiveFedora #:nodoc:
|
|
|
68
67
|
autoload :FedoraAttributes
|
|
69
68
|
autoload :File
|
|
70
69
|
autoload :FileConfigurator
|
|
70
|
+
autoload :FileIO
|
|
71
71
|
autoload :FilePathBuilder
|
|
72
72
|
autoload :FilePersistence
|
|
73
73
|
autoload :FileRelation
|
|
74
74
|
autoload :FilesHash
|
|
75
|
-
autoload :Filter
|
|
76
75
|
autoload :FixityService
|
|
77
76
|
autoload :Identifiable
|
|
78
77
|
autoload :Indexers
|
|
@@ -89,6 +88,7 @@ module ActiveFedora #:nodoc:
|
|
|
89
88
|
autoload :ModelClassifier
|
|
90
89
|
autoload :NestedAttributes
|
|
91
90
|
autoload :NullRelation
|
|
91
|
+
autoload :NullLogger
|
|
92
92
|
autoload :Orders
|
|
93
93
|
autoload :Pathing
|
|
94
94
|
autoload :Persistence
|
|
@@ -196,11 +196,11 @@ module ActiveFedora #:nodoc:
|
|
|
196
196
|
# ActiveFedora.environment => "test"
|
|
197
197
|
def environment
|
|
198
198
|
if config_options.fetch(:environment, nil)
|
|
199
|
-
|
|
199
|
+
config_options[:environment]
|
|
200
200
|
elsif defined?(Rails.env) && !Rails.env.nil?
|
|
201
|
-
|
|
201
|
+
Rails.env.to_s
|
|
202
202
|
elsif defined?(ENV['environment']) && !ENV['environment'].nil?
|
|
203
|
-
|
|
203
|
+
ENV['environment']
|
|
204
204
|
elsif defined?(ENV['RAILS_ENV']) && !ENV['RAILS_ENV'].nil?
|
|
205
205
|
raise "You're depending on RAILS_ENV for setting your environment. Please use ENV['environment'] for non-rails environment setting: 'rake foo:bar environment=test'"
|
|
206
206
|
else
|
|
@@ -242,16 +242,14 @@ module ActiveFedora #:nodoc:
|
|
|
242
242
|
end
|
|
243
243
|
|
|
244
244
|
def index_field_mapper
|
|
245
|
-
|
|
245
|
+
@index_field_mapper ||= Indexing::FieldMapper.new
|
|
246
246
|
end
|
|
247
247
|
|
|
248
248
|
def id_field
|
|
249
249
|
if defined?(SOLR_DOCUMENT_ID) && !SOLR_DOCUMENT_ID.nil?
|
|
250
250
|
SOLR_DOCUMENT_ID
|
|
251
|
-
elsif defined?(Solrizer)
|
|
252
|
-
Solrizer.default_field_mapper.id_field
|
|
253
251
|
else
|
|
254
|
-
|
|
252
|
+
ActiveFedora.index_field_mapper.id_field
|
|
255
253
|
end
|
|
256
254
|
end
|
|
257
255
|
|
|
@@ -262,6 +260,22 @@ module ActiveFedora #:nodoc:
|
|
|
262
260
|
true
|
|
263
261
|
end
|
|
264
262
|
end
|
|
263
|
+
|
|
264
|
+
# ActiveSupport::Autoload automatically defines
|
|
265
|
+
# an eager_load! method. In this case, we are
|
|
266
|
+
# extending the method to also eager load the
|
|
267
|
+
# components inside ActiveFedora.
|
|
268
|
+
def eager_load!
|
|
269
|
+
super
|
|
270
|
+
ActiveFedora::Scoping.eager_load!
|
|
271
|
+
ActiveFedora::Aggregation.eager_load!
|
|
272
|
+
ActiveFedora::Associations.eager_load!
|
|
273
|
+
ActiveFedora::Attributes.eager_load!
|
|
274
|
+
ActiveFedora::AttributeMethods.eager_load!
|
|
275
|
+
ActiveFedora::Indexers.eager_load!
|
|
276
|
+
ActiveFedora::Indexing.eager_load!
|
|
277
|
+
ActiveFedora::Orders.eager_load!
|
|
278
|
+
end
|
|
265
279
|
end
|
|
266
280
|
|
|
267
281
|
self.configurator ||= ActiveFedora::FileConfigurator.new
|