active-fedora 10.1.0 → 11.1.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/.gitignore +1 -0
- data/.rubocop.yml +6 -7
- data/.rubocop_todo.yml +55 -0
- data/.solr_wrapper +6 -0
- data/.travis.yml +6 -9
- data/Gemfile +1 -0
- data/History.txt +34 -0
- data/README.md +1 -3
- data/active-fedora.gemspec +7 -13
- data/lib/active_fedora/aggregation/list_source.rb +2 -0
- data/lib/active_fedora/associations/association_scope.rb +1 -1
- data/lib/active_fedora/associations/builder/aggregation.rb +1 -1
- data/lib/active_fedora/associations/builder/association.rb +1 -1
- data/lib/active_fedora/associations/builder/orders.rb +11 -3
- data/lib/active_fedora/associations/collection_association.rb +5 -5
- data/lib/active_fedora/associations/collection_proxy.rb +10 -10
- data/lib/active_fedora/associations/contained_finder.rb +2 -2
- data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +1 -1
- data/lib/active_fedora/associations/has_many_association.rb +2 -2
- data/lib/active_fedora/associations/has_subresource_association.rb +2 -2
- data/lib/active_fedora/associations/orders_association.rb +4 -0
- data/lib/active_fedora/associations/rdf.rb +2 -0
- data/lib/active_fedora/attribute_assignment.rb +0 -1
- data/lib/active_fedora/attribute_methods/dirty.rb +1 -1
- data/lib/active_fedora/attribute_methods.rb +1 -1
- data/lib/active_fedora/attributes.rb +1 -1
- data/lib/active_fedora/base.rb +4 -8
- data/lib/active_fedora/change_set.rb +6 -2
- data/lib/active_fedora/cleaner.rb +1 -1
- data/lib/active_fedora/containers/container.rb +1 -1
- data/lib/active_fedora/core.rb +33 -30
- data/lib/active_fedora/fedora.rb +6 -2
- data/lib/active_fedora/fedora_attributes.rb +1 -1
- data/lib/active_fedora/file/streaming.rb +1 -1
- data/lib/active_fedora/file.rb +2 -1
- data/lib/active_fedora/file_configurator.rb +3 -3
- data/lib/active_fedora/indexing.rb +1 -18
- data/lib/active_fedora/indexing_service.rb +0 -9
- data/lib/active_fedora/initializing_connection.rb +1 -1
- data/lib/active_fedora/loadable_from_json.rb +12 -1
- data/lib/active_fedora/model_classifier.rb +1 -1
- data/lib/active_fedora/nested_attributes.rb +2 -2
- data/lib/active_fedora/null_logger.rb +10 -0
- data/lib/active_fedora/orders/list_node.rb +2 -2
- data/lib/active_fedora/orders/ordered_list.rb +8 -4
- data/lib/active_fedora/orders/target_proxy.rb +4 -0
- data/lib/active_fedora/querying.rb +1 -1
- data/lib/active_fedora/railtie.rb +2 -2
- data/lib/active_fedora/rake_support.rb +1 -1
- data/lib/active_fedora/rdf/field_map_entry.rb +6 -0
- data/lib/active_fedora/rdf/persistence.rb +1 -0
- data/lib/active_fedora/rdf/value_caster.rb +15 -0
- data/lib/active_fedora/rdf.rb +1 -1
- data/lib/active_fedora/relation/delegation.rb +4 -0
- data/lib/active_fedora/relation/finder_methods.rb +3 -1
- data/lib/active_fedora/solr_hit.rb +1 -14
- data/lib/active_fedora/solr_query_builder.rb +17 -13
- data/lib/active_fedora/version.rb +1 -1
- data/lib/active_fedora/with_metadata/metadata_node.rb +2 -1
- data/lib/active_fedora.rb +1 -12
- data/lib/generators/active_fedora/config/solr/templates/solr/config/solrconfig.xml +11 -0
- data/lib/generators/active_fedora/config/solr/templates/solr_wrapper_test.yml +1 -1
- data/lib/generators/active_fedora/model/model_generator.rb +1 -1
- data/lib/generators/active_fedora/model/templates/model.rb.erb +4 -4
- data/lib/tasks/active_fedora_dev.rake +1 -1
- data/spec/config_helper.rb +1 -1
- data/spec/integration/associations_spec.rb +23 -24
- data/spec/integration/attached_files_spec.rb +19 -9
- data/spec/integration/attributes_spec.rb +12 -16
- data/spec/integration/autosave_association_spec.rb +6 -6
- data/spec/integration/base_spec.rb +8 -8
- data/spec/integration/basic_contains_association_spec.rb +1 -1
- data/spec/integration/clean_connection_spec.rb +1 -1
- data/spec/integration/collection_association_spec.rb +2 -5
- data/spec/integration/date_time_properties_spec.rb +1 -17
- data/spec/integration/direct_container_spec.rb +12 -12
- data/spec/integration/directly_contains_one_association_spec.rb +11 -13
- data/spec/integration/eradicate_spec.rb +1 -1
- data/spec/integration/fedora_solr_sync_spec.rb +2 -2
- data/spec/integration/file_fixity_spec.rb +6 -8
- data/spec/integration/file_spec.rb +37 -39
- data/spec/integration/generators/solr_generator_spec.rb +7 -10
- data/spec/integration/has_and_belongs_to_many_associations_spec.rb +7 -7
- data/spec/integration/has_many_associations_spec.rb +9 -11
- data/spec/integration/indexing_spec.rb +2 -2
- data/spec/integration/indirect_container_spec.rb +11 -12
- data/spec/integration/json_serialization_spec.rb +4 -4
- data/spec/integration/query_result_builder_spec.rb +9 -21
- data/spec/integration/rdf_nested_attributes_spec.rb +7 -7
- data/spec/integration/relation_delegation_spec.rb +8 -10
- data/spec/integration/relation_spec.rb +13 -16
- data/spec/integration/scoped_query_spec.rb +3 -3
- data/spec/integration/scoping_spec.rb +3 -3
- data/spec/integration/solr_hit_spec.rb +4 -15
- data/spec/integration/versionable_spec.rb +73 -327
- data/spec/integration/with_metadata_spec.rb +1 -1
- data/spec/spec_helper.rb +52 -10
- data/spec/unit/active_fedora_spec.rb +1 -1
- data/spec/unit/aggregation/list_source_spec.rb +37 -37
- data/spec/unit/aggregation/ordered_reader_spec.rb +4 -4
- data/spec/unit/association_hash_spec.rb +17 -31
- data/spec/unit/attached_files_spec.rb +35 -32
- data/spec/unit/attributes_spec.rb +25 -25
- data/spec/unit/base_active_model_spec.rb +8 -8
- data/spec/unit/base_cma_spec.rb +1 -1
- data/spec/unit/base_extra_spec.rb +7 -22
- data/spec/unit/base_spec.rb +21 -27
- 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 +5 -5
- data/spec/unit/checksum_spec.rb +2 -2
- data/spec/unit/code_configurator_spec.rb +1 -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 +68 -32
- data/spec/unit/default_model_mapper_spec.rb +6 -6
- data/spec/unit/fedora_spec.rb +3 -4
- data/spec/unit/file_configurator_spec.rb +96 -96
- data/spec/unit/file_path_builder_spec.rb +3 -3
- data/spec/unit/file_spec.rb +93 -61
- data/spec/unit/files_hash_spec.rb +9 -9
- data/spec/unit/filter_spec.rb +3 -3
- data/spec/unit/finder_methods_spec.rb +3 -3
- data/spec/unit/forbidden_attributes_protection_spec.rb +2 -2
- data/spec/unit/has_and_belongs_to_many_association_spec.rb +14 -15
- data/spec/unit/has_many_association_spec.rb +28 -13
- data/spec/unit/indexers/global_indexer_spec.rb +6 -6
- data/spec/unit/indexing_service_spec.rb +5 -5
- data/spec/unit/indexing_spec.rb +8 -8
- data/spec/unit/inheritance_spec.rb +11 -7
- data/spec/unit/loadable_from_json_spec.rb +4 -4
- data/spec/unit/logger_spec.rb +1 -1
- data/spec/unit/model_classifier_spec.rb +5 -5
- data/spec/unit/ordered_spec.rb +144 -147
- data/spec/unit/orders/list_node_spec.rb +22 -22
- data/spec/unit/orders/ordered_list_spec.rb +96 -96
- data/spec/unit/orders/reflection_spec.rb +4 -4
- data/spec/unit/pathing_spec.rb +4 -4
- data/spec/unit/persistence_spec.rb +28 -28
- data/spec/unit/property_spec.rb +2 -2
- data/spec/unit/query_spec.rb +12 -12
- data/spec/unit/rdf/indexing_service_spec.rb +29 -29
- data/spec/unit/readonly_spec.rb +5 -4
- data/spec/unit/reflection_spec.rb +3 -3
- data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +9 -9
- data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +9 -9
- data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +9 -9
- data/spec/unit/schema_indexing_strategy_spec.rb +5 -5
- data/spec/unit/serializers_spec.rb +3 -4
- data/spec/unit/solr_config_options_spec.rb +13 -16
- data/spec/unit/solr_hit_spec.rb +9 -9
- data/spec/unit/solr_service_spec.rb +4 -10
- data/spec/unit/sparql_insert_spec.rb +2 -2
- data/spec/unit/validations_spec.rb +12 -12
- data/spec/unit/with_metadata/default_metadata_class_factory_spec.rb +3 -2
- data/spec/unit/with_metadata/metadata_node_spec.rb +3 -2
- metadata +30 -130
- data/lib/active_fedora/datastreams/nokogiri_datastreams.rb +0 -119
- data/lib/active_fedora/datastreams.rb +0 -6
- data/lib/active_fedora/nom_datastream.rb +0 -73
- data/lib/active_fedora/om_datastream.rb +0 -118
- data/lib/active_fedora/profile_indexing_service.rb +0 -11
- data/lib/active_fedora/qualified_dublin_core_datastream.rb +0 -158
- data/lib/active_fedora/rdf/datastream_indexing.rb +0 -49
- data/lib/active_fedora/rdf/ntriples_rdf_datastream.rb +0 -13
- data/lib/active_fedora/rdf/rdf_datastream.rb +0 -167
- data/lib/active_fedora/rdf/rdfxml_datastream.rb +0 -13
- data/lib/active_fedora/solr_instance_loader.rb +0 -47
- data/solr/config/_rest_managed.json +0 -3
- data/solr/config/admin-extra.html +0 -31
- data/solr/config/elevate.xml +0 -36
- data/solr/config/mapping-ISOLatin1Accent.txt +0 -246
- data/solr/config/protwords.txt +0 -21
- data/solr/config/schema.xml +0 -372
- data/solr/config/scripts.conf +0 -24
- data/solr/config/solrconfig.xml +0 -311
- data/solr/config/spellings.txt +0 -2
- data/solr/config/stopwords.txt +0 -58
- data/solr/config/stopwords_en.txt +0 -58
- data/solr/config/synonyms.txt +0 -31
- data/solr/config/xslt/example.xsl +0 -132
- data/solr/config/xslt/example_atom.xsl +0 -67
- data/solr/config/xslt/example_rss.xsl +0 -66
- data/solr/config/xslt/luke.xsl +0 -337
- data/spec/fixtures/damsObjectModel.xml +0 -38
- data/spec/fixtures/dublin_core_rdf_descMetadata.nt +0 -13
- data/spec/fixtures/mixed_rdf_descMetadata.nt +0 -7
- data/spec/fixtures/mods_articles/mods_article1.xml +0 -98
- data/spec/fixtures/solr_rdf_descMetadata.nt +0 -7
- data/spec/integration/complex_rdf_datastream_spec.rb +0 -228
- data/spec/integration/datastream_rdf_nested_attributes_spec.rb +0 -179
- data/spec/integration/ntriples_datastream_spec.rb +0 -203
- data/spec/integration/om_datastream_spec.rb +0 -78
- data/spec/integration/solr_instance_loader_spec.rb +0 -156
- data/spec/samples/hydra-mods_article_datastream.rb +0 -517
- data/spec/samples/models/mods_article.rb +0 -9
- data/spec/samples/oral_history_sample.xml +0 -38
- data/spec/samples/oral_history_xml.xml +0 -35
- data/spec/samples/samples.rb +0 -2
- data/spec/unit/nom_datastream_spec.rb +0 -60
- data/spec/unit/ntriples_datastream_spec.rb +0 -170
- data/spec/unit/om_datastream_spec.rb +0 -294
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +0 -119
- data/spec/unit/rdf_datastream_spec.rb +0 -84
- data/spec/unit/rdf_resource_datastream_spec.rb +0 -204
- data/spec/unit/rdfxml_datastream_spec.rb +0 -106
data/lib/active_fedora/core.rb
CHANGED
|
@@ -8,13 +8,19 @@ module ActiveFedora
|
|
|
8
8
|
autoload :FedoraUriTranslator
|
|
9
9
|
|
|
10
10
|
included do
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
#
|
|
11
|
+
mattr_accessor :belongs_to_required_by_default, instance_accessor: false
|
|
12
|
+
|
|
14
13
|
# Accepts a logger conforming to the interface of Log4r which can be
|
|
15
14
|
# retrieved on both a class and instance level by calling +logger+.
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
class_attribute :logger
|
|
16
|
+
|
|
17
|
+
# Use NullLogger as the default and all messages sent to it are retuned as nil
|
|
18
|
+
self.logger = ActiveFedora::NullLogger.new
|
|
19
|
+
|
|
20
|
+
# All instances default to the class-level logger
|
|
21
|
+
def logger
|
|
22
|
+
self.class.logger
|
|
23
|
+
end
|
|
18
24
|
end
|
|
19
25
|
|
|
20
26
|
# Constructor. You may supply a custom +:id+, or we call the Fedora Rest API for the
|
|
@@ -22,14 +28,14 @@ module ActiveFedora
|
|
|
22
28
|
# Also, if +attrs+ does not contain +:id+ but does contain +:namespace+ it will pass the
|
|
23
29
|
# +:namespace+ value to Fedora::Repository.nextid to generate the next id available within
|
|
24
30
|
# the given namespace.
|
|
25
|
-
def initialize(
|
|
31
|
+
def initialize(attributes = nil, &_block)
|
|
26
32
|
init_internals
|
|
27
|
-
|
|
28
|
-
@ldp_source = build_ldp_resource(
|
|
33
|
+
id = attributes && (attributes.delete(:id) || attributes.delete('id'))
|
|
34
|
+
@ldp_source = build_ldp_resource(id)
|
|
29
35
|
raise IllegalOperation, "Attempting to recreate existing ldp_source: `#{ldp_source.subject}'" unless ldp_source.new?
|
|
36
|
+
assign_attributes(attributes) if attributes
|
|
30
37
|
assert_content_model
|
|
31
38
|
load_attached_files
|
|
32
|
-
assign_attributes(attributes) if attributes
|
|
33
39
|
|
|
34
40
|
yield self if block_given?
|
|
35
41
|
_run_initialize_callbacks
|
|
@@ -96,13 +102,14 @@ module ActiveFedora
|
|
|
96
102
|
|
|
97
103
|
protected
|
|
98
104
|
|
|
99
|
-
# This
|
|
100
|
-
# It's normally called once in the lifecycle, by #create#
|
|
105
|
+
# This method is normally called once in the lifecycle, by #create#
|
|
101
106
|
def assert_content_model
|
|
102
|
-
self.has_model = self.class.
|
|
107
|
+
self.has_model = self.class.to_rdf_representation
|
|
103
108
|
end
|
|
104
109
|
|
|
105
110
|
module ClassMethods
|
|
111
|
+
extend Deprecation
|
|
112
|
+
|
|
106
113
|
def generated_association_methods
|
|
107
114
|
@generated_association_methods ||= begin
|
|
108
115
|
mod = const_set(:GeneratedAssociationMethods, Module.new)
|
|
@@ -111,13 +118,23 @@ module ActiveFedora
|
|
|
111
118
|
end
|
|
112
119
|
end
|
|
113
120
|
|
|
114
|
-
# Returns a suitable
|
|
115
|
-
#
|
|
116
|
-
#
|
|
117
|
-
def
|
|
121
|
+
# Returns a suitable string representation for :has_model
|
|
122
|
+
# Override this method if you want to change how this class
|
|
123
|
+
# is represented in RDF.
|
|
124
|
+
def to_rdf_representation
|
|
118
125
|
name
|
|
119
126
|
end
|
|
120
127
|
|
|
128
|
+
# Returns a suitable string representation for :has_model
|
|
129
|
+
# @deprecated use to_rdf_representation instead
|
|
130
|
+
def to_class_uri(attrs = nil)
|
|
131
|
+
if attrs
|
|
132
|
+
Deprecation.warn ActiveFedora::Core, "to_class_uri no longer acceps an argument"
|
|
133
|
+
end
|
|
134
|
+
to_rdf_representation
|
|
135
|
+
end
|
|
136
|
+
deprecation_deprecate to_class_uri: "use 'to_rdf_representation()' instead"
|
|
137
|
+
|
|
121
138
|
private
|
|
122
139
|
|
|
123
140
|
def relation
|
|
@@ -144,19 +161,5 @@ module ActiveFedora
|
|
|
144
161
|
raise ActiveFedora::ObjectNotFoundError, "Can't reload an object that hasn't been saved"
|
|
145
162
|
end
|
|
146
163
|
end
|
|
147
|
-
|
|
148
|
-
def initialize_attributes(attributes_or_id)
|
|
149
|
-
case attributes_or_id
|
|
150
|
-
when String
|
|
151
|
-
attributes = { id: attributes_or_id }.with_indifferent_access
|
|
152
|
-
when Hash
|
|
153
|
-
attributes = attributes_or_id.with_indifferent_access
|
|
154
|
-
when NilClass
|
|
155
|
-
attributes = {}.with_indifferent_access
|
|
156
|
-
else
|
|
157
|
-
raise ArgumentError, "#{attributes_or_id.class} is not acceptable"
|
|
158
|
-
end
|
|
159
|
-
attributes
|
|
160
|
-
end
|
|
161
164
|
end
|
|
162
165
|
end
|
data/lib/active_fedora/fedora.rb
CHANGED
|
@@ -23,11 +23,15 @@ module ActiveFedora
|
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def host
|
|
26
|
-
@config[:url]
|
|
26
|
+
@config[:url].sub(/\/$/, BLANK)
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
def base_path
|
|
30
|
-
@config[:base_path] ||
|
|
30
|
+
@config[:base_path] || SLASH
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def base_uri
|
|
34
|
+
host + base_path.sub(/\/$/, BLANK)
|
|
31
35
|
end
|
|
32
36
|
|
|
33
37
|
def user
|
|
@@ -43,7 +43,7 @@ module ActiveFedora
|
|
|
43
43
|
# Appending the graph at the end is necessary because adding it as the
|
|
44
44
|
# parent leaves behind triples not related to the ldp_source's rdf
|
|
45
45
|
# subject.
|
|
46
|
-
@resource ||= self.class.resource_class.new(@ldp_source.graph.rdf_subject, @ldp_source.graph
|
|
46
|
+
@resource ||= self.class.resource_class.new(@ldp_source.graph.rdf_subject, data: @ldp_source.graph.graph.data)
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
# You can set the URI to use for the rdf_label on ClassMethods.rdf_label, then on
|
|
@@ -23,7 +23,7 @@ module ActiveFedora::File::Streaming
|
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def each(no_of_requests_limit = 3, &block)
|
|
26
|
-
raise ArgumentError, 'HTTP redirect too deep' if no_of_requests_limit
|
|
26
|
+
raise ArgumentError, 'HTTP redirect too deep' if no_of_requests_limit.zero?
|
|
27
27
|
Net::HTTP.start(uri.host, uri.port, use_ssl: (uri.scheme == 'https')) do |http|
|
|
28
28
|
request = Net::HTTP::Get.new uri, headers
|
|
29
29
|
http.request request do |response|
|
data/lib/active_fedora/file.rb
CHANGED
|
@@ -30,7 +30,8 @@ module ActiveFedora
|
|
|
30
30
|
# @yield [self] Yields self
|
|
31
31
|
# @yieldparam [File] self the newly created file
|
|
32
32
|
def initialize(identifier = nil, &_block)
|
|
33
|
-
identifier =
|
|
33
|
+
identifier = identifier.delete(:id) if identifier.is_a? Hash
|
|
34
|
+
identifier = identifier.uri if identifier.respond_to? :uri
|
|
34
35
|
run_callbacks(:initialize) do
|
|
35
36
|
case identifier
|
|
36
37
|
when nil, ::RDF::URI
|
|
@@ -99,7 +99,7 @@ module ActiveFedora
|
|
|
99
99
|
def load_fedora_config
|
|
100
100
|
return @fedora_config unless @fedora_config.empty?
|
|
101
101
|
@fedora_config_path = config_path(:fedora)
|
|
102
|
-
ActiveFedora::Base.logger.info("ActiveFedora: loading fedora config from #{::File.expand_path(@fedora_config_path)}")
|
|
102
|
+
ActiveFedora::Base.logger.info("ActiveFedora: loading fedora config from #{::File.expand_path(@fedora_config_path)}")
|
|
103
103
|
|
|
104
104
|
begin
|
|
105
105
|
config_erb = ERB.new(IO.read(@fedora_config_path)).result(binding)
|
|
@@ -124,7 +124,7 @@ module ActiveFedora
|
|
|
124
124
|
return @solr_config unless @solr_config.empty?
|
|
125
125
|
@solr_config_path = config_path(:solr)
|
|
126
126
|
|
|
127
|
-
ActiveFedora::Base.logger.info "ActiveFedora: loading solr config from #{::File.expand_path(@solr_config_path)}"
|
|
127
|
+
ActiveFedora::Base.logger.info "ActiveFedora: loading solr config from #{::File.expand_path(@solr_config_path)}"
|
|
128
128
|
begin
|
|
129
129
|
config_erb = ERB.new(IO.read(@solr_config_path)).result(binding)
|
|
130
130
|
rescue StandardError
|
|
@@ -188,7 +188,7 @@ module ActiveFedora
|
|
|
188
188
|
# Last choice, check for the default config file
|
|
189
189
|
config_path = ::File.join(ActiveFedora.root, "config", "#{config_type}.yml")
|
|
190
190
|
if ::File.file? config_path
|
|
191
|
-
ActiveFedora::Base.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."
|
|
191
|
+
ActiveFedora::Base.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."
|
|
192
192
|
return config_path
|
|
193
193
|
else
|
|
194
194
|
raise ConfigurationError, "Couldn't load #{config_type} config file!"
|
|
@@ -10,7 +10,6 @@ module ActiveFedora
|
|
|
10
10
|
module Indexing
|
|
11
11
|
extend ActiveSupport::Concern
|
|
12
12
|
extend ActiveSupport::Autoload
|
|
13
|
-
extend Deprecation
|
|
14
13
|
|
|
15
14
|
eager_autoload do
|
|
16
15
|
autoload :Map
|
|
@@ -84,7 +83,7 @@ module ActiveFedora
|
|
|
84
83
|
end
|
|
85
84
|
|
|
86
85
|
def reindex_everything
|
|
87
|
-
descendants = descendant_uris(ActiveFedora
|
|
86
|
+
descendants = descendant_uris(ActiveFedora.fedora.base_uri)
|
|
88
87
|
descendants.shift # Discard the root uri
|
|
89
88
|
descendants.each do |uri|
|
|
90
89
|
logger.debug "Re-index everything ... #{uri}"
|
|
@@ -92,22 +91,6 @@ module ActiveFedora
|
|
|
92
91
|
end
|
|
93
92
|
end
|
|
94
93
|
|
|
95
|
-
# This method can be used instead of ActiveFedora::Model::ClassMethods.find.
|
|
96
|
-
# It works similarly except it populates an object from Solr instead of Fedora.
|
|
97
|
-
# It is most useful for objects used in read-only displays in order to speed up loading time. If only
|
|
98
|
-
# a id is passed in it will query solr for a corresponding solr document and then use it
|
|
99
|
-
# to populate this object.
|
|
100
|
-
#
|
|
101
|
-
# If a value is passed in for optional parameter solr_doc it will not query solr again and just use the
|
|
102
|
-
# one passed to populate the object.
|
|
103
|
-
#
|
|
104
|
-
# It will anything stored within solr such as metadata and relationships. Non-metadata attached files will not
|
|
105
|
-
# be loaded and if needed you should use find instead.
|
|
106
|
-
def load_instance_from_solr(id, solr_doc = nil)
|
|
107
|
-
SolrInstanceLoader.new(self, id, solr_doc).object
|
|
108
|
-
end
|
|
109
|
-
deprecation_deprecate :load_instance_from_solr
|
|
110
|
-
|
|
111
94
|
def descendant_uris(uri)
|
|
112
95
|
resource = Ldp::Resource::RdfSource.new(ActiveFedora.fedora.connection, uri)
|
|
113
96
|
# GET could be slow if it's a big resource, we're using HEAD to avoid this problem,
|
|
@@ -15,10 +15,6 @@ module ActiveFedora
|
|
|
15
15
|
@object = obj
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
def self.profile_solr_name
|
|
19
|
-
@profile_solr_name ||= ActiveFedora.index_field_mapper.solr_name("object_profile", :displayable)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
18
|
def self.create_time_solr_name
|
|
23
19
|
@create_time_solr_name ||= ActiveFedora.index_field_mapper.solr_name('system_create', :stored_sortable, type: :date)
|
|
24
20
|
end
|
|
@@ -40,7 +36,6 @@ module ActiveFedora
|
|
|
40
36
|
Solrizer.set_field(solr_doc, 'system_modified', m_time, :stored_sortable)
|
|
41
37
|
solr_doc[QueryResultBuilder::HAS_MODEL_SOLR_FIELD] = object.has_model
|
|
42
38
|
solr_doc[ActiveFedora.id_field.to_sym] = object.id
|
|
43
|
-
solr_doc[self.class.profile_solr_name] = profile_service.new(object).export
|
|
44
39
|
object.declared_attached_files.each do |name, file|
|
|
45
40
|
solr_doc.merge! file.to_solr(solr_doc, name: name.to_s)
|
|
46
41
|
end
|
|
@@ -51,10 +46,6 @@ module ActiveFedora
|
|
|
51
46
|
|
|
52
47
|
protected
|
|
53
48
|
|
|
54
|
-
def profile_service
|
|
55
|
-
ProfileIndexingService
|
|
56
|
-
end
|
|
57
|
-
|
|
58
49
|
def c_time
|
|
59
50
|
c_time = object.create_date.present? ? object.create_date : DateTime.now
|
|
60
51
|
c_time = DateTime.parse(c_time) unless c_time.is_a?(DateTime)
|
|
@@ -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
|
|
@@ -50,6 +50,10 @@ module ActiveFedora
|
|
|
50
50
|
@hash[k]
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
+
def persist!(*)
|
|
54
|
+
true
|
|
55
|
+
end
|
|
56
|
+
|
|
53
57
|
# FakeQuery exists to adapt the hash to the RDF interface used by RDF associations in ActiveFedora
|
|
54
58
|
class FakeQuery
|
|
55
59
|
include ::Enumerable
|
|
@@ -153,7 +157,7 @@ module ActiveFedora
|
|
|
153
157
|
# @param attribute_name [String] the name of the attribute to adapt
|
|
154
158
|
# @return [Object] the adapted value
|
|
155
159
|
def adapt_attribute_value(attrs, attribute_name)
|
|
156
|
-
reflection =
|
|
160
|
+
reflection = property_reflection(attribute_name)
|
|
157
161
|
# if this isn't a property, copy value verbatim
|
|
158
162
|
return attrs[attribute_name] unless reflection
|
|
159
163
|
multiple = reflection.multiple?
|
|
@@ -169,6 +173,13 @@ module ActiveFedora
|
|
|
169
173
|
end
|
|
170
174
|
end
|
|
171
175
|
|
|
176
|
+
def property_reflection(attribute_name)
|
|
177
|
+
self.class.reflect_on_property(attribute_name)
|
|
178
|
+
rescue ActiveTriples::UndefinedPropertyError
|
|
179
|
+
ActiveFedora::Base.logger.info "Undefined property #{attribute_name} reflected."
|
|
180
|
+
nil
|
|
181
|
+
end
|
|
182
|
+
|
|
172
183
|
def date_attribute?(attribute_name)
|
|
173
184
|
reflection = self.class.reflect_on_property(attribute_name)
|
|
174
185
|
return false unless reflection
|
|
@@ -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)
|
|
@@ -159,7 +159,7 @@ module ActiveFedora
|
|
|
159
159
|
|
|
160
160
|
# Attribute hash keys that should not be assigned as normal attributes.
|
|
161
161
|
# These hash keys are nested attributes implementation details.
|
|
162
|
-
UNASSIGNABLE_KEYS = %w(
|
|
162
|
+
UNASSIGNABLE_KEYS = %w(id _destroy).freeze
|
|
163
163
|
|
|
164
164
|
# Assigns the given attributes to the association.
|
|
165
165
|
#
|
|
@@ -308,7 +308,7 @@ module ActiveFedora
|
|
|
308
308
|
opts = nested_attributes_options[association_name]
|
|
309
309
|
case callback = opts[:reject_if]
|
|
310
310
|
when Symbol
|
|
311
|
-
method(callback).arity
|
|
311
|
+
method(callback).arity.zero? ? send(callback) : send(callback, attributes)
|
|
312
312
|
when Proc
|
|
313
313
|
callback.call(attributes)
|
|
314
314
|
end
|
|
@@ -4,7 +4,7 @@ module ActiveFedora::Orders
|
|
|
4
4
|
attr_accessor :prev, :next, :target
|
|
5
5
|
attr_writer :next_uri, :prev_uri
|
|
6
6
|
attr_accessor :proxy_in, :proxy_for
|
|
7
|
-
def initialize(node_cache, rdf_subject, graph = RDF::
|
|
7
|
+
def initialize(node_cache, rdf_subject, graph = RDF::Repository.new)
|
|
8
8
|
@rdf_subject = rdf_subject
|
|
9
9
|
@graph = graph
|
|
10
10
|
@node_cache = node_cache
|
|
@@ -144,7 +144,7 @@ module ActiveFedora::Orders
|
|
|
144
144
|
private
|
|
145
145
|
|
|
146
146
|
def resource
|
|
147
|
-
@resource ||= Resource.new(uri, graph)
|
|
147
|
+
@resource ||= Resource.new(uri, data: graph)
|
|
148
148
|
end
|
|
149
149
|
end
|
|
150
150
|
|
|
@@ -13,7 +13,11 @@ module ActiveFedora
|
|
|
13
13
|
# @param [::RDF::URI] head_subject URI of head node in list.
|
|
14
14
|
# @param [::RDF::URI] tail_subject URI of tail node in list.
|
|
15
15
|
def initialize(graph, head_subject, tail_subject)
|
|
16
|
-
@graph = graph
|
|
16
|
+
@graph = if graph.respond_to?(:graph)
|
|
17
|
+
graph.graph.data
|
|
18
|
+
else
|
|
19
|
+
graph
|
|
20
|
+
end
|
|
17
21
|
@head_subject = head_subject
|
|
18
22
|
@tail_subject = tail_subject
|
|
19
23
|
@node_cache ||= NodeCache.new
|
|
@@ -86,7 +90,7 @@ module ActiveFedora
|
|
|
86
90
|
node = build_node(new_node_subject)
|
|
87
91
|
node.target = target
|
|
88
92
|
node.proxy_in = proxy_in
|
|
89
|
-
if loc
|
|
93
|
+
if loc.zero?
|
|
90
94
|
append_to(node, head)
|
|
91
95
|
else
|
|
92
96
|
append_to(node, ordered_reader.take(loc).last)
|
|
@@ -99,7 +103,7 @@ module ActiveFedora
|
|
|
99
103
|
node = build_node(new_node_subject)
|
|
100
104
|
node.proxy_for = proxy_for
|
|
101
105
|
node.proxy_in = proxy_in
|
|
102
|
-
if loc
|
|
106
|
+
if loc.zero?
|
|
103
107
|
append_to(node, head)
|
|
104
108
|
else
|
|
105
109
|
append_to(node, ordered_reader.take(loc).last)
|
|
@@ -170,7 +174,7 @@ module ActiveFedora
|
|
|
170
174
|
def proxy_in
|
|
171
175
|
proxies = to_a.map(&:proxy_in_id).compact.uniq
|
|
172
176
|
if proxies.length > 1
|
|
173
|
-
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."
|
|
174
178
|
end
|
|
175
179
|
proxies.first
|
|
176
180
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module ActiveFedora
|
|
2
2
|
module Querying
|
|
3
3
|
delegate :find, :first, :exists?, :where, :limit, :offset, :order, :delete_all,
|
|
4
|
-
:destroy_all, :count, :last, :
|
|
4
|
+
:destroy_all, :count, :last, :search_with_conditions, :search_in_batches, :search_by_id, :find_each, to: :all
|
|
5
5
|
|
|
6
6
|
def self.extended(base)
|
|
7
7
|
base.class_attribute :solr_query_handler
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module ActiveFedora
|
|
2
2
|
class Railtie < Rails::Railtie
|
|
3
|
-
config.app_middleware.insert_after
|
|
4
|
-
|
|
3
|
+
config.app_middleware.insert_after ::ActionDispatch::Callbacks,
|
|
4
|
+
ActiveFedora::LdpCache
|
|
5
5
|
|
|
6
6
|
initializer 'active_fedora.autoload', before: :set_autoload_paths do |app|
|
|
7
7
|
app.config.autoload_paths << 'app/models/datastreams'
|
|
@@ -21,7 +21,7 @@ def with_server(environment)
|
|
|
21
21
|
unless Dir.exist?(solr_config_path)
|
|
22
22
|
$stderr.puts "Solr configuration not found at #{solr_config_path}. Using ActiveFedora defaults"
|
|
23
23
|
# Otherwise use the configs delivered with ActiveFedora.
|
|
24
|
-
solr_config_path = File.join(File.expand_path("../..", File.dirname(__FILE__)),
|
|
24
|
+
solr_config_path = File.join(File.expand_path("../..", File.dirname(__FILE__)), 'lib', 'generators', 'active_fedora', 'config', 'solr', 'templates', 'solr', 'config')
|
|
25
25
|
end
|
|
26
26
|
solr.with_collection(name: "hydra-#{environment}", dir: solr_config_path) do
|
|
27
27
|
FcrepoWrapper.wrap(load_config(:fcrepo, environment, fcrepo_defaults)) do |fcrepo|
|
data/lib/active_fedora/rdf.rb
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
module ActiveFedora
|
|
2
2
|
module RDF
|
|
3
3
|
extend ActiveSupport::Autoload
|
|
4
|
-
autoload :DatastreamIndexing
|
|
5
4
|
autoload :Fcrepo
|
|
6
5
|
autoload :IndexingService
|
|
7
6
|
autoload :Persistence
|
|
8
7
|
autoload :ProjectHydra
|
|
9
8
|
autoload :FieldMap
|
|
10
9
|
autoload :FieldMapEntry
|
|
10
|
+
autoload :ValueCaster
|
|
11
11
|
end
|
|
12
12
|
end
|
|
@@ -130,7 +130,7 @@ module ActiveFedora
|
|
|
130
130
|
begin
|
|
131
131
|
yield(load_from_fedora(hit[ActiveFedora.id_field], cast))
|
|
132
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."
|
|
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."
|
|
134
134
|
end
|
|
135
135
|
end
|
|
136
136
|
end
|
|
@@ -240,11 +240,13 @@ module ActiveFedora
|
|
|
240
240
|
|
|
241
241
|
# Returns a solr query for the supplied conditions
|
|
242
242
|
# @param[Hash,String,Array] conditions solr conditions to match
|
|
243
|
+
# @return [String]
|
|
243
244
|
def create_query(conditions)
|
|
244
245
|
build_query(build_where(conditions))
|
|
245
246
|
end
|
|
246
247
|
|
|
247
248
|
# @param [Array<String>] conditions
|
|
249
|
+
# @return [String]
|
|
248
250
|
def build_query(conditions)
|
|
249
251
|
clauses = search_model_clause ? [search_model_clause] : []
|
|
250
252
|
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
|
|
|
@@ -46,15 +46,6 @@ module ActiveFedora
|
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
def instantiate_with_json
|
|
50
|
-
model.allocate.init_with_json(profile_json) do |allocated_object|
|
|
51
|
-
create_key = allocated_object.indexing_service.class.create_time_solr_name
|
|
52
|
-
modified_key = allocated_object.indexing_service.class.modified_time_solr_name
|
|
53
|
-
allocated_object.resource.set_value(:create_date, DateTime.parse(document[create_key])) if document[create_key]
|
|
54
|
-
allocated_object.resource.set_value(:modified_date, DateTime.parse(document[modified_key])) if document[modified_key]
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
49
|
def reify(opts = {})
|
|
59
50
|
model(opts).find(id, cast: true)
|
|
60
51
|
end
|
|
@@ -64,9 +55,5 @@ module ActiveFedora
|
|
|
64
55
|
def classifier
|
|
65
56
|
ActiveFedora.model_mapper.classifier(document)
|
|
66
57
|
end
|
|
67
|
-
|
|
68
|
-
def profile_json
|
|
69
|
-
Array(document[ActiveFedora::IndexingService.profile_solr_name]).first
|
|
70
|
-
end
|
|
71
58
|
end
|
|
72
59
|
end
|
|
@@ -11,29 +11,30 @@ module ActiveFedora
|
|
|
11
11
|
"{!terms f=#{ActiveFedora.id_field}}#{ids.join(',')}"
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
# Create a query with a clause for each key, value
|
|
14
|
+
# Create a raw query with a clause for each key, value
|
|
15
15
|
# @param [Hash, Array<Array<String>>] field_pairs key is the predicate, value is the target_uri
|
|
16
16
|
# @param [String] join_with ('AND') the value we're joining the clauses with
|
|
17
17
|
# @example
|
|
18
|
-
# construct_query_for_rel [[:has_model, "
|
|
19
|
-
# # => _query_:"{!
|
|
18
|
+
# construct_query_for_rel [[:has_model, "ComplexCollection"], [:has_model, "ActiveFedora_Base"]], 'OR'
|
|
19
|
+
# # => _query_:"{!raw f=has_model_ssim}ComplexCollection" OR _query_:"{!raw f=has_model_ssim}ActiveFedora_Base"
|
|
20
20
|
#
|
|
21
21
|
# construct_query_for_rel [[Book._reflect_on_association(:library), "foo/bar/baz"]]
|
|
22
22
|
def construct_query_for_rel(field_pairs, join_with = default_join_with)
|
|
23
23
|
field_pairs = field_pairs.to_a if field_pairs.is_a? Hash
|
|
24
|
-
construct_query(property_values_to_solr(field_pairs), join_with)
|
|
24
|
+
construct_query(property_values_to_solr(field_pairs), join_with, 'raw'.freeze)
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
# Construct a solr query from a list of pairs (e.g. [field name, values])
|
|
28
28
|
# @param [Array<Array>] field_pairs a list of pairs of property name and values
|
|
29
29
|
# @param [String] join_with ('AND') the value we're joining the clauses with
|
|
30
|
+
# @param [String] type ('field') The type of query to run. Either 'raw' or 'field'
|
|
30
31
|
# @return [String] a solr query
|
|
31
32
|
# @example
|
|
32
33
|
# construct_query([['library_id_ssim', '123'], ['owner_ssim', 'Fred']])
|
|
33
34
|
# # => "_query_:\"{!field f=library_id_ssim}123\" AND _query_:\"{!field f=owner_ssim}Fred\""
|
|
34
|
-
def construct_query(field_pairs, join_with = default_join_with)
|
|
35
|
-
clauses = pairs_to_clauses(field_pairs)
|
|
36
|
-
return "" if clauses.count
|
|
35
|
+
def construct_query(field_pairs, join_with = default_join_with, type = 'field'.freeze)
|
|
36
|
+
clauses = pairs_to_clauses(field_pairs, type)
|
|
37
|
+
return "" if clauses.count.zero?
|
|
37
38
|
return clauses.first if clauses.count == 1
|
|
38
39
|
"(#{clauses.join(join_with)})"
|
|
39
40
|
end
|
|
@@ -45,22 +46,24 @@ module ActiveFedora
|
|
|
45
46
|
private
|
|
46
47
|
|
|
47
48
|
# @param [Array<Array>] pairs a list of (key, value) pairs. The value itself may
|
|
49
|
+
# @param [String] type The type of query to run. Either 'raw' or 'field'
|
|
48
50
|
# @return [Array] a list of solr clauses
|
|
49
|
-
def pairs_to_clauses(pairs)
|
|
51
|
+
def pairs_to_clauses(pairs, type)
|
|
50
52
|
pairs.flat_map do |field, value|
|
|
51
|
-
condition_to_clauses(field, value)
|
|
53
|
+
condition_to_clauses(field, value, type)
|
|
52
54
|
end
|
|
53
55
|
end
|
|
54
56
|
|
|
55
57
|
# @param [String] field
|
|
56
58
|
# @param [String, Array<String>] values
|
|
59
|
+
# @param [String] type The type of query to run. Either 'raw' or 'field'
|
|
57
60
|
# @return [Array<String>]
|
|
58
|
-
def condition_to_clauses(field, values)
|
|
61
|
+
def condition_to_clauses(field, values, type)
|
|
59
62
|
values = Array(values)
|
|
60
63
|
values << nil if values.empty?
|
|
61
64
|
values.map do |value|
|
|
62
65
|
if value.present?
|
|
63
|
-
|
|
66
|
+
query_clause(type, field, value)
|
|
64
67
|
else
|
|
65
68
|
# Check that the field is not present. In SQL: "WHERE field IS NULL"
|
|
66
69
|
"-#{field}:[* TO *]"
|
|
@@ -93,10 +96,11 @@ module ActiveFedora
|
|
|
93
96
|
end
|
|
94
97
|
|
|
95
98
|
# Create a raw query clause suitable for sending to solr as an fq element
|
|
99
|
+
# @param [String] type The type of query to run. Either 'raw' or 'field'
|
|
96
100
|
# @param [String] key
|
|
97
101
|
# @param [String] value
|
|
98
|
-
def
|
|
99
|
-
"_query_:\"{
|
|
102
|
+
def query_clause(type, key, value)
|
|
103
|
+
"_query_:\"{!#{type} f=#{key}}#{value.gsub('"', '\"')}\""
|
|
100
104
|
end
|
|
101
105
|
end
|
|
102
106
|
end
|