active-fedora 8.7.0 → 9.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +8 -15
- data/Gemfile +5 -5
- data/History.txt +0 -80
- data/README.md +1 -0
- data/Rakefile +0 -3
- data/active-fedora.gemspec +8 -7
- data/config/fedora.yml +5 -4
- data/config/predicate_mappings.yml +5 -5
- data/gemfiles/rails4.1.gemfile +10 -0
- data/gemfiles/rails4.2.beta.gemfile +10 -0
- data/lib/active_fedora.rb +151 -117
- data/lib/active_fedora/associations.rb +47 -15
- data/lib/active_fedora/associations/association.rb +29 -8
- data/lib/active_fedora/associations/association_scope.rb +5 -5
- data/lib/active_fedora/associations/belongs_to_association.rb +20 -63
- data/lib/active_fedora/associations/builder/association.rb +61 -25
- data/lib/active_fedora/associations/builder/belongs_to.rb +7 -94
- data/lib/active_fedora/associations/builder/collection_association.rb +11 -43
- data/lib/active_fedora/associations/builder/contains.rb +28 -0
- data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +13 -3
- data/lib/active_fedora/associations/builder/has_many.rb +16 -10
- data/lib/active_fedora/associations/builder/property.rb +14 -0
- data/lib/active_fedora/associations/builder/singular_association.rb +14 -18
- data/lib/active_fedora/associations/builder/singular_property.rb +12 -0
- data/lib/active_fedora/associations/collection_association.rb +57 -80
- data/lib/active_fedora/associations/contains_association.rb +50 -0
- data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +44 -24
- data/lib/active_fedora/associations/has_many_association.rb +46 -14
- data/lib/active_fedora/associations/rdf.rb +86 -0
- data/lib/active_fedora/associations/singular_association.rb +4 -8
- data/lib/active_fedora/associations/singular_rdf.rb +15 -0
- data/lib/active_fedora/attached_files.rb +195 -0
- data/lib/active_fedora/attribute_methods.rb +122 -0
- data/lib/active_fedora/attribute_methods/dirty.rb +16 -0
- data/lib/active_fedora/attribute_methods/read.rb +61 -0
- data/lib/active_fedora/attribute_methods/write.rb +47 -0
- data/lib/active_fedora/attributes.rb +93 -44
- data/lib/active_fedora/attributes/primary_key.rb +12 -0
- data/lib/active_fedora/autosave_association.rb +2 -2
- data/lib/active_fedora/base.rb +16 -15
- data/lib/active_fedora/callbacks.rb +7 -7
- data/lib/active_fedora/change_set.rb +34 -0
- data/lib/active_fedora/cleaner.rb +62 -0
- data/lib/active_fedora/config.rb +4 -22
- data/lib/active_fedora/core.rb +173 -99
- data/lib/active_fedora/datastream.rb +4 -117
- data/lib/active_fedora/datastreams.rb +2 -263
- data/lib/active_fedora/datastreams/nokogiri_datastreams.rb +28 -51
- data/lib/active_fedora/{datastream_attribute.rb → delegated_attribute.rb} +57 -26
- data/lib/active_fedora/errors.rb +61 -0
- data/lib/active_fedora/fedora.rb +19 -0
- data/lib/active_fedora/fedora_attributes.rb +58 -26
- data/lib/active_fedora/file.rb +318 -0
- data/lib/active_fedora/file_configurator.rb +32 -32
- data/lib/active_fedora/file_path_builder.rb +24 -0
- data/lib/active_fedora/files_hash.rb +82 -0
- data/lib/active_fedora/fixity_service.rb +40 -0
- data/lib/active_fedora/indexing.rb +55 -82
- data/lib/active_fedora/indexing_service.rb +70 -0
- data/lib/active_fedora/ldp_resource.rb +26 -0
- data/lib/active_fedora/loadable_from_json.rb +112 -0
- data/lib/active_fedora/model.rb +5 -19
- data/lib/active_fedora/nested_attributes.rb +5 -6
- data/lib/active_fedora/nom_datastream.rb +15 -25
- data/lib/active_fedora/om_datastream.rb +26 -197
- data/lib/active_fedora/persistence.rb +95 -71
- data/lib/active_fedora/predicates.rb +4 -4
- data/lib/active_fedora/qualified_dublin_core_datastream.rb +17 -18
- data/lib/active_fedora/querying.rb +3 -4
- data/lib/active_fedora/railtie.rb +3 -6
- data/lib/active_fedora/rdf.rb +3 -1
- data/lib/active_fedora/rdf/datastream_indexing.rb +11 -0
- data/lib/active_fedora/rdf/fcrepo.rb +10 -324
- data/lib/active_fedora/rdf/indexing.rb +20 -16
- data/lib/active_fedora/rdf/ldp.rb +6 -0
- data/lib/active_fedora/rdf/ntriples_rdf_datastream.rb +1 -1
- data/lib/active_fedora/rdf/persistence.rb +5 -6
- data/lib/active_fedora/rdf/rdf_datastream.rb +44 -37
- data/lib/active_fedora/rdf/rdfxml_datastream.rb +13 -0
- data/lib/active_fedora/rdf/rels_ext.rb +26 -0
- data/lib/active_fedora/reflection.rb +256 -199
- data/lib/active_fedora/relation.rb +18 -6
- data/lib/active_fedora/relation/finder_methods.rb +69 -38
- data/lib/active_fedora/relation/query_methods.rb +7 -3
- data/lib/active_fedora/rspec_matchers/belong_to_associated_active_fedora_object_matcher.rb +7 -7
- data/lib/active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher.rb +8 -8
- data/lib/active_fedora/rspec_matchers/have_predicate_matcher.rb +9 -11
- data/lib/active_fedora/simple_datastream.rb +18 -13
- data/lib/active_fedora/solr_instance_loader.rb +18 -38
- data/lib/active_fedora/solr_service.rb +37 -20
- data/lib/active_fedora/sparql_insert.rb +45 -0
- data/lib/active_fedora/test_support.rb +1 -22
- data/lib/active_fedora/version.rb +1 -1
- data/lib/active_fedora/versionable.rb +90 -0
- data/lib/active_fedora/with_metadata.rb +37 -0
- data/lib/active_fedora/with_metadata/metadata_node.rb +70 -0
- data/lib/generators/active_fedora/config/config_generator.rb +0 -1
- data/lib/generators/active_fedora/config/solr/solr_generator.rb +1 -1
- data/lib/generators/active_fedora/model/model_generator.rb +5 -5
- data/lib/generators/active_fedora/model/templates/datastream_spec.rb.erb +1 -1
- data/lib/generators/active_fedora/model/templates/model_spec.rb.erb +2 -2
- data/lib/tasks/active_fedora_dev.rake +21 -27
- data/spec/config_helper.rb +1 -1
- data/spec/fixtures/mixed_rdf_descMetadata.nt +6 -6
- data/spec/fixtures/rails_root/config/predicate_mappings.yml +3 -19
- data/spec/fixtures/solr_rdf_descMetadata.nt +6 -6
- data/spec/integration/associations_spec.rb +133 -153
- data/spec/integration/attached_files_spec.rb +164 -0
- data/spec/integration/attributes_spec.rb +73 -12
- data/spec/integration/autosave_association_spec.rb +3 -3
- data/spec/integration/base_spec.rb +57 -351
- data/spec/integration/belongs_to_association_spec.rb +86 -76
- data/spec/integration/bug_spec.rb +3 -3
- data/spec/integration/collection_association_spec.rb +4 -4
- data/spec/integration/complex_rdf_datastream_spec.rb +54 -56
- data/spec/integration/delete_all_spec.rb +18 -15
- data/spec/integration/eradicate_spec.rb +54 -0
- data/spec/integration/fedora_solr_sync_spec.rb +7 -5
- data/spec/integration/field_to_solr_name_spec.rb +5 -5
- data/spec/integration/file_fixity_spec.rb +40 -0
- data/spec/integration/file_spec.rb +122 -0
- data/spec/integration/full_featured_model_spec.rb +53 -63
- data/spec/integration/has_and_belongs_to_many_associations_spec.rb +141 -114
- data/spec/integration/has_many_associations_spec.rb +142 -64
- data/spec/integration/json_serialization_spec.rb +50 -8
- data/spec/integration/model_spec.rb +12 -29
- data/spec/integration/nested_attribute_spec.rb +28 -20
- data/spec/integration/ntriples_datastream_spec.rb +60 -57
- data/spec/integration/om_datastream_spec.rb +51 -140
- data/spec/integration/rdf_nested_attributes_spec.rb +16 -14
- data/spec/integration/relation_delegation_spec.rb +7 -9
- data/spec/integration/relation_spec.rb +9 -7
- data/spec/integration/scoped_query_spec.rb +26 -26
- data/spec/integration/solr_instance_loader_spec.rb +69 -53
- data/spec/integration/solr_service_spec.rb +12 -73
- data/spec/integration/versionable_spec.rb +477 -0
- data/spec/integration/with_metadata_spec.rb +52 -0
- data/spec/samples/hydra-mods_article_datastream.rb +10 -6
- data/spec/samples/models/mods_article.rb +6 -2
- data/spec/samples/oral_history_sample.xml +1 -1
- data/spec/samples/oral_history_xml.xml +1 -1
- data/spec/samples/special_thing.rb +3 -3
- data/spec/spec_helper.rb +22 -12
- data/spec/support/an_active_model.rb +3 -7
- data/spec/unit/active_fedora_spec.rb +20 -17
- data/spec/unit/attached_files_spec.rb +203 -0
- data/spec/unit/attributes_spec.rb +286 -207
- data/spec/unit/base_active_model_spec.rb +8 -8
- data/spec/unit/base_datastream_management_spec.rb +11 -24
- data/spec/unit/base_extra_spec.rb +17 -67
- data/spec/unit/base_spec.rb +163 -428
- data/spec/unit/builder/has_and_belongs_to_many_spec.rb +2 -2
- data/spec/unit/callback_spec.rb +38 -23
- data/spec/unit/change_set_spec.rb +46 -0
- data/spec/unit/code_configurator_spec.rb +5 -5
- data/spec/unit/config_spec.rb +9 -14
- data/spec/unit/core_spec.rb +59 -8
- data/spec/unit/file_configurator_spec.rb +55 -53
- data/spec/unit/file_path_builder_spec.rb +18 -0
- data/spec/unit/file_spec.rb +221 -0
- data/spec/unit/files_hash_spec.rb +53 -0
- data/spec/unit/fixity_service_spec.rb +34 -0
- data/spec/unit/has_and_belongs_to_many_association_spec.rb +134 -0
- data/spec/unit/has_many_association_spec.rb +51 -0
- data/spec/unit/indexing_service_spec.rb +23 -0
- data/spec/unit/indexing_spec.rb +26 -0
- data/spec/unit/inheritance_spec.rb +9 -10
- data/spec/unit/model_spec.rb +15 -33
- data/spec/unit/nom_datastream_spec.rb +13 -10
- data/spec/unit/ntriples_datastream_spec.rb +81 -96
- data/spec/unit/om_datastream_spec.rb +137 -227
- data/spec/unit/persistence_spec.rb +28 -34
- data/spec/unit/predicates_spec.rb +29 -29
- data/spec/unit/property_spec.rb +1 -3
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +27 -32
- data/spec/unit/query_spec.rb +116 -149
- data/spec/unit/rdf_datastream_spec.rb +25 -43
- data/spec/unit/rdf_resource_datastream_spec.rb +24 -123
- data/spec/unit/{rdfxml_rdf_datastream_spec.rb → rdfxml_datastream_spec.rb} +21 -25
- data/spec/unit/readonly_spec.rb +23 -0
- data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +6 -6
- data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +6 -6
- data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +6 -6
- data/spec/unit/serializers_spec.rb +1 -1
- data/spec/unit/simple_datastream_spec.rb +12 -23
- data/spec/unit/solr_config_options_spec.rb +14 -17
- data/spec/unit/solr_service_spec.rb +38 -77
- data/spec/unit/sparql_insert_spec.rb +32 -0
- data/spec/unit/validations_spec.rb +8 -11
- metadata +96 -121
- data/lib/active_fedora/auditable.rb +0 -9
- data/lib/active_fedora/content_model.rb +0 -70
- data/lib/active_fedora/datastream_collections.rb +0 -302
- data/lib/active_fedora/datastream_hash.rb +0 -35
- data/lib/active_fedora/digital_object.rb +0 -55
- data/lib/active_fedora/fixture_exporter.rb +0 -33
- data/lib/active_fedora/fixture_loader.rb +0 -48
- data/lib/active_fedora/rdf/identifiable.rb +0 -66
- data/lib/active_fedora/rdf/project_hydra.rb +0 -12
- data/lib/active_fedora/rdf/rdfxml_rdf_datastream.rb +0 -13
- data/lib/active_fedora/rdf_xml_writer.rb +0 -49
- data/lib/active_fedora/relationship_graph.rb +0 -101
- data/lib/active_fedora/reload_on_save.rb +0 -16
- data/lib/active_fedora/rels_ext_datastream.rb +0 -100
- data/lib/active_fedora/rspec_matchers/match_fedora_datastream_matcher.rb +0 -41
- data/lib/active_fedora/rubydora_connection.rb +0 -35
- data/lib/active_fedora/semantic_node.rb +0 -164
- data/lib/active_fedora/service_definitions.rb +0 -88
- data/lib/active_fedora/sharding.rb +0 -58
- data/lib/active_fedora/solr_digital_object.rb +0 -68
- data/lib/active_fedora/unsaved_digital_object.rb +0 -58
- data/lib/generators/active_fedora/config/fedora/fedora_generator.rb +0 -12
- data/lib/generators/active_fedora/config/fedora/templates/fedora.yml +0 -38
- data/lib/generators/active_fedora/config/fedora/templates/fedora_conf/conf/development/fedora.fcfg +0 -953
- data/lib/generators/active_fedora/config/fedora/templates/fedora_conf/conf/test/fedora.fcfg +0 -953
- data/lib/tasks/active_fedora.rake +0 -83
- data/spec/fixtures/sharded_fedora.yml +0 -11
- data/spec/integration/auditable_spec.rb +0 -29
- data/spec/integration/datastream_collections_spec.rb +0 -127
- data/spec/integration/datastream_spec.rb +0 -90
- data/spec/integration/datastreams_spec.rb +0 -173
- data/spec/integration/load_from_solr_spec.rb +0 -66
- data/spec/integration/rels_ext_datastream_spec.rb +0 -82
- data/spec/support/mock_fedora.rb +0 -44
- data/spec/unit/content_model_spec.rb +0 -86
- data/spec/unit/datastream_collections_spec.rb +0 -420
- data/spec/unit/datastream_spec.rb +0 -83
- data/spec/unit/datastreams_spec.rb +0 -243
- data/spec/unit/has_and_belongs_to_many_collection_spec.rb +0 -96
- data/spec/unit/has_many_collection_spec.rb +0 -35
- data/spec/unit/rdf_vocab_spec.rb +0 -30
- data/spec/unit/rdf_xml_writer_spec.rb +0 -63
- data/spec/unit/relationship_graph_spec.rb +0 -115
- data/spec/unit/reload_on_save_spec.rb +0 -24
- data/spec/unit/rels_ext_datastream_spec.rb +0 -170
- data/spec/unit/rspec_matchers/match_fedora_datastream_matcher_spec.rb +0 -44
- data/spec/unit/rubydora_connection_spec.rb +0 -12
- data/spec/unit/semantic_node_spec.rb +0 -112
- data/spec/unit/service_definitions_spec.rb +0 -63
- data/spec/unit/solr_digital_object_spec.rb +0 -97
- data/spec/unit/unsaved_digital_object_spec.rb +0 -48
@@ -7,37 +7,37 @@ module ActiveFedora
|
|
7
7
|
# Initializes ActiveFedora's connection to Fedora and Solr based on the info in fedora.yml and solr.yml
|
8
8
|
# NOTE: this deprecates the use of a solr url in the fedora.yml
|
9
9
|
#
|
10
|
-
#
|
10
|
+
#
|
11
11
|
# If Rails.env is set, it will use that environment. Defaults to "development".
|
12
12
|
# @param [Hash] options (optional) a list of options for the configuration of active_fedora
|
13
13
|
# @option options [String] :environment The environment within which to run
|
14
14
|
# @option options [String] :fedora_config_path The full path to the fedora.yml config file.
|
15
15
|
# @option options [String] :solr_config_path The full path to the solr.yml config file.
|
16
|
-
#
|
17
|
-
# If :environment is not set, order of preference is
|
16
|
+
#
|
17
|
+
# If :environment is not set, order of preference is
|
18
18
|
# 1. Rails.env
|
19
19
|
# 2. ENV['environment']
|
20
20
|
# 3. RAILS_ENV
|
21
21
|
#
|
22
|
-
# If :fedora_config_path is not set, it will look in
|
22
|
+
# If :fedora_config_path is not set, it will look in
|
23
23
|
# 1. +Rails.root+/config
|
24
24
|
# 2. +current working directory+/config
|
25
25
|
# 3. (default) the fedora.yml shipped with gem
|
26
26
|
#
|
27
|
-
# If :solr_config_path is not set, it will
|
27
|
+
# If :solr_config_path is not set, it will
|
28
28
|
# 1. look in config_options[:fedora_config_path]. If it finds a solr.yml there, it will use it.
|
29
|
-
# 2. If it does not find a solr.yml and the fedora.yml contains a solr url, it will raise an configuration error
|
29
|
+
# 2. If it does not find a solr.yml and the fedora.yml contains a solr url, it will raise an configuration error
|
30
30
|
# 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
|
31
31
|
|
32
32
|
# Options allowed in fedora.yml
|
33
|
-
# first level is the environment (e.g. development, test, production and any custom environments you may have)
|
33
|
+
# first level is the environment (e.g. development, test, production and any custom environments you may have)
|
34
34
|
# the second level has these keys:
|
35
35
|
# 1. url: url including protocol, host, port and path (e.g. http://127.0.0.1:8983/fedora)
|
36
36
|
# 2. user: username
|
37
37
|
# 3. password: password
|
38
|
-
# 4. validateChecksum: indicates to the fedora server whether you want to validate checksums when the datastreams are queried.
|
38
|
+
# 4. validateChecksum: indicates to the fedora server whether you want to validate checksums when the datastreams are queried.
|
39
39
|
#
|
40
|
-
# @example If you want to shard the fedora instance, you can specify an array of credentials.
|
40
|
+
# @example If you want to shard the fedora instance, you can specify an array of credentials.
|
41
41
|
# production:
|
42
42
|
# - user: user1
|
43
43
|
# password: password1
|
@@ -56,7 +56,7 @@ module ActiveFedora
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def init options = {}
|
59
|
-
if options.is_a?(String)
|
59
|
+
if options.is_a?(String)
|
60
60
|
raise ArgumentError, "Calling ActiveFedora.init with a path as an argument has been removed. Use ActiveFedora.init(:fedora_config_path=>#{options})"
|
61
61
|
end
|
62
62
|
reset!
|
@@ -76,7 +76,7 @@ module ActiveFedora
|
|
76
76
|
def path
|
77
77
|
get_config_path(:fedora)
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
def reset!
|
81
81
|
@config_loaded = false #Force reload of configs
|
82
82
|
@fedora_config = {}
|
@@ -92,7 +92,7 @@ module ActiveFedora
|
|
92
92
|
def load_configs
|
93
93
|
return if config_loaded?
|
94
94
|
@config_env = ActiveFedora.environment
|
95
|
-
|
95
|
+
|
96
96
|
load_fedora_config
|
97
97
|
load_solr_config
|
98
98
|
@config_loaded = true
|
@@ -101,7 +101,7 @@ module ActiveFedora
|
|
101
101
|
def load_fedora_config
|
102
102
|
return @fedora_config unless @fedora_config.empty?
|
103
103
|
@fedora_config_path = get_config_path(:fedora)
|
104
|
-
ActiveFedora::Base.logger.info("ActiveFedora: loading fedora config from #{File.expand_path(@fedora_config_path)}") if ActiveFedora::Base.logger
|
104
|
+
ActiveFedora::Base.logger.info("ActiveFedora: loading fedora config from #{::File.expand_path(@fedora_config_path)}") if ActiveFedora::Base.logger
|
105
105
|
|
106
106
|
begin
|
107
107
|
config_erb = ERB.new(IO.read(@fedora_config_path)).result(binding)
|
@@ -126,7 +126,7 @@ module ActiveFedora
|
|
126
126
|
return @solr_config unless @solr_config.empty?
|
127
127
|
@solr_config_path = get_config_path(:solr)
|
128
128
|
|
129
|
-
ActiveFedora::Base.logger.info "ActiveFedora: loading solr config from #{File.expand_path(@solr_config_path)}" if ActiveFedora::Base.logger
|
129
|
+
ActiveFedora::Base.logger.info "ActiveFedora: loading solr config from #{::File.expand_path(@solr_config_path)}" if ActiveFedora::Base.logger
|
130
130
|
begin
|
131
131
|
config_erb = ERB.new(IO.read(@solr_config_path)).result(binding)
|
132
132
|
rescue Exception => e
|
@@ -144,7 +144,7 @@ module ActiveFedora
|
|
144
144
|
@solr_config = {:url=> get_solr_url(config[ActiveFedora.environment.to_sym].symbolize_keys)}
|
145
145
|
end
|
146
146
|
|
147
|
-
# Given the solr_config that's been loaded for this environment,
|
147
|
+
# Given the solr_config that's been loaded for this environment,
|
148
148
|
# determine which solr url to use
|
149
149
|
def get_solr_url(solr_config)
|
150
150
|
if @index_full_text == true && solr_config.has_key?(:fulltext) && solr_config[:fulltext].has_key?('url')
|
@@ -159,7 +159,7 @@ module ActiveFedora
|
|
159
159
|
raise URI::InvalidURIError
|
160
160
|
end
|
161
161
|
end
|
162
|
-
|
162
|
+
|
163
163
|
# Determine the fedora config file to use. Order of preference is:
|
164
164
|
# 1. Use the config_options[:config_path] if it exists
|
165
165
|
# 2. Look in +Rails.root+/config/fedora.yml
|
@@ -170,10 +170,10 @@ module ActiveFedora
|
|
170
170
|
def get_config_path(config_type)
|
171
171
|
config_type = config_type.to_s
|
172
172
|
if (config_path = config_options.fetch("#{config_type}_config_path".to_sym,nil) )
|
173
|
-
raise ConfigurationError, "file does not exist #{config_path}" unless File.file? config_path
|
174
|
-
return File.expand_path(config_path)
|
173
|
+
raise ConfigurationError, "file does not exist #{config_path}" unless ::File.file? config_path
|
174
|
+
return ::File.expand_path(config_path)
|
175
175
|
end
|
176
|
-
|
176
|
+
|
177
177
|
# if solr, attempt to use path where fedora.yml is first
|
178
178
|
if config_type == "solr" && (config_path = check_fedora_path_for_solr)
|
179
179
|
return config_path
|
@@ -181,27 +181,27 @@ module ActiveFedora
|
|
181
181
|
|
182
182
|
if defined?(Rails.root)
|
183
183
|
config_path = "#{Rails.root}/config/#{config_type}.yml"
|
184
|
-
return config_path if File.file? config_path
|
184
|
+
return config_path if ::File.file? config_path
|
185
185
|
end
|
186
|
-
|
187
|
-
if File.file? "#{Dir.getwd}/config/#{config_type}.yml"
|
186
|
+
|
187
|
+
if ::File.file? "#{Dir.getwd}/config/#{config_type}.yml"
|
188
188
|
return "#{Dir.getwd}/config/#{config_type}.yml"
|
189
189
|
end
|
190
|
-
|
190
|
+
|
191
191
|
# Last choice, check for the default config file
|
192
|
-
config_path = File.join(ActiveFedora.root, "config", "#{config_type}.yml")
|
193
|
-
if File.file? config_path
|
192
|
+
config_path = ::File.join(ActiveFedora.root, "config", "#{config_type}.yml")
|
193
|
+
if ::File.file? config_path
|
194
194
|
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." if ActiveFedora::Base.logger
|
195
195
|
return config_path
|
196
196
|
else
|
197
197
|
raise ConfigurationError, "Couldn't load #{config_type} config file!"
|
198
198
|
end
|
199
199
|
end
|
200
|
-
|
200
|
+
|
201
201
|
# Checks the existing fedora_config.path to see if there is a solr.yml there
|
202
202
|
def check_fedora_path_for_solr
|
203
|
-
path = File.dirname(self.path) + "/solr.yml"
|
204
|
-
if File.file? path
|
203
|
+
path = ::File.dirname(self.path) + "/solr.yml"
|
204
|
+
if ::File.file? path
|
205
205
|
return path
|
206
206
|
else
|
207
207
|
return nil
|
@@ -210,21 +210,21 @@ module ActiveFedora
|
|
210
210
|
|
211
211
|
def predicate_config
|
212
212
|
@predicate_config_path ||= build_predicate_config_path
|
213
|
-
YAML.load(File.open(@predicate_config_path)) if File.exist?(@predicate_config_path)
|
213
|
+
YAML.load(::File.open(@predicate_config_path)) if ::File.exist?(@predicate_config_path)
|
214
214
|
end
|
215
215
|
|
216
216
|
protected
|
217
217
|
|
218
218
|
def build_predicate_config_path
|
219
|
-
testfile = File.expand_path(get_config_path(:predicate_mappings))
|
220
|
-
if File.exist?(testfile) && valid_predicate_mapping?(testfile)
|
219
|
+
testfile = ::File.expand_path(get_config_path(:predicate_mappings))
|
220
|
+
if ::File.exist?(testfile) && valid_predicate_mapping?(testfile)
|
221
221
|
return testfile
|
222
222
|
end
|
223
223
|
raise PredicateMappingsNotFoundError
|
224
224
|
end
|
225
225
|
|
226
226
|
def valid_predicate_mapping?(testfile)
|
227
|
-
mapping = YAML.load(File.open(testfile))
|
227
|
+
mapping = YAML.load(::File.open(testfile))
|
228
228
|
return false unless mapping.has_key?(:default_namespace) && mapping[:default_namespace].is_a?(String)
|
229
229
|
return false unless mapping.has_key?(:predicate_mapping) && mapping[:predicate_mapping].is_a?(Hash)
|
230
230
|
true
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module ActiveFedora
|
2
|
+
class FilePathBuilder
|
3
|
+
# Builds a relative path for a file
|
4
|
+
def self.build(digital_object, name, prefix)
|
5
|
+
name = nil if name == ''
|
6
|
+
prefix ||= 'DS'
|
7
|
+
name || generate_dsid(digital_object, prefix)
|
8
|
+
end
|
9
|
+
|
10
|
+
# return a valid dsid that is not currently in use. Uses a prefix (default "DS") and an auto-incrementing integer
|
11
|
+
# Example: if there are already datastreams with IDs DS1 and DS2, this method will return DS3. If you specify FOO as the prefix, it will return FOO1.
|
12
|
+
def self.generate_dsid(digital_object, prefix)
|
13
|
+
return unless digital_object
|
14
|
+
matches = digital_object.attached_files.keys.map {|d| data = /^#{prefix}(\d+)$/.match(d); data && data[1].to_i}.compact
|
15
|
+
val = matches.empty? ? 1 : matches.max + 1
|
16
|
+
format_dsid(prefix, val)
|
17
|
+
end
|
18
|
+
|
19
|
+
### Provided so that an application can override how generated ids are formatted (e.g DS01 instead of DS1)
|
20
|
+
def self.format_dsid(prefix, suffix)
|
21
|
+
sprintf("%s%i", prefix,suffix)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module ActiveFedora
|
4
|
+
class FilesHash
|
5
|
+
extend Forwardable
|
6
|
+
|
7
|
+
def initialize (model)
|
8
|
+
@base = model
|
9
|
+
end
|
10
|
+
|
11
|
+
def [] (name)
|
12
|
+
association(name).reader if association(name)
|
13
|
+
end
|
14
|
+
|
15
|
+
def []= (name, object)
|
16
|
+
association(name).writer(object) if association(name)
|
17
|
+
end
|
18
|
+
|
19
|
+
def association(name)
|
20
|
+
# Check to see if the key exists before casting to a symbol, because symbols
|
21
|
+
# are not garbage collected in earlier versions of Ruby
|
22
|
+
@base.association(name.to_sym) if key?(name)
|
23
|
+
end
|
24
|
+
|
25
|
+
def reflections
|
26
|
+
@base.class.child_resource_reflections
|
27
|
+
end
|
28
|
+
|
29
|
+
def each
|
30
|
+
keys.each do |k|
|
31
|
+
yield k, self[k]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def keys
|
36
|
+
reflections.keys + @base.undeclared_files
|
37
|
+
end
|
38
|
+
|
39
|
+
# Check that the key exists with indifferent access (symbol or string) in a
|
40
|
+
# manner that avoids generating extra symbols. Symbols are not garbage collected
|
41
|
+
# in earlier versions of ruby.
|
42
|
+
def key?(key)
|
43
|
+
keys.include?(key) || keys.map(&:to_s).include?(key)
|
44
|
+
end
|
45
|
+
|
46
|
+
def values
|
47
|
+
keys.map { |k| self[k] }
|
48
|
+
end
|
49
|
+
|
50
|
+
def has_key?(key)
|
51
|
+
keys.include?(key)
|
52
|
+
end
|
53
|
+
|
54
|
+
def size
|
55
|
+
keys.size
|
56
|
+
end
|
57
|
+
|
58
|
+
def empty?
|
59
|
+
reflections.empty?
|
60
|
+
end
|
61
|
+
|
62
|
+
def each_value
|
63
|
+
keys.each do |k|
|
64
|
+
yield self[k]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def select
|
69
|
+
keys.each_with_object({}) do |k, h|
|
70
|
+
val = self[k]
|
71
|
+
h[k] = val if yield k, val
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def freeze
|
76
|
+
keys.each do |name|
|
77
|
+
association(name).reader.freeze if association(name).loaded?
|
78
|
+
end
|
79
|
+
super
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module ActiveFedora
|
2
|
+
class FixityService
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
attr_accessor :target, :response
|
6
|
+
|
7
|
+
# Accepts an Fedora resource such as File.ldp_resource.subject
|
8
|
+
def initialize target
|
9
|
+
raise ArgumentError, 'You must provide a uri' unless target
|
10
|
+
@target = target
|
11
|
+
end
|
12
|
+
|
13
|
+
# Executes a fixity check on Fedora and saves the Faraday::Response.
|
14
|
+
# Returns true when the fixity check was successfully.
|
15
|
+
def check
|
16
|
+
@response = get_fixity_response_from_fedora
|
17
|
+
status.match("SUCCESS") ? true : false
|
18
|
+
end
|
19
|
+
|
20
|
+
def status
|
21
|
+
fixity_graph.query(predicate: status_url).map(&:object).first.to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def get_fixity_response_from_fedora
|
27
|
+
uri = target + "/fcr:fixity"
|
28
|
+
ActiveFedora.fedora.connection.get(uri)
|
29
|
+
end
|
30
|
+
|
31
|
+
def fixity_graph
|
32
|
+
::RDF::Graph.new << ::RDF::Reader.for(:ttl).new(response.body)
|
33
|
+
end
|
34
|
+
|
35
|
+
def status_url
|
36
|
+
::RDF::URI("http://fedora.info/definitions/v4/repository#status")
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -2,119 +2,92 @@ module ActiveFedora
|
|
2
2
|
module Indexing
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
|
-
included do
|
6
|
-
class_attribute :profile_solr_name
|
7
|
-
self.profile_solr_name = ActiveFedora::SolrService.solr_name("object_profile", :displayable)
|
8
|
-
end
|
9
|
-
|
10
5
|
# Return a Hash representation of this object where keys in the hash are appropriate Solr field names.
|
11
6
|
# @param [Hash] solr_doc (optional) Hash to insert the fields into
|
12
7
|
# @param [Hash] opts (optional)
|
13
8
|
# If opts[:model_only] == true, the base object metadata and the RELS-EXT datastream will be omitted. This is mainly to support shelver, which calls .to_solr for each model an object subscribes to.
|
14
9
|
def to_solr(solr_doc = Hash.new, opts={})
|
15
|
-
|
16
|
-
c_time = create_date
|
17
|
-
c_time = Time.parse(c_time) unless c_time.is_a?(Time)
|
18
|
-
m_time = modified_date
|
19
|
-
m_time = Time.parse(m_time) unless m_time.is_a?(Time)
|
20
|
-
Solrizer.set_field(solr_doc, 'system_create', c_time, :stored_sortable)
|
21
|
-
Solrizer.set_field(solr_doc, 'system_modified', m_time, :stored_sortable)
|
22
|
-
Solrizer.set_field(solr_doc, 'object_state', state, :stored_sortable)
|
23
|
-
Solrizer.set_field(solr_doc, 'active_fedora_model', has_model, :stored_sortable)
|
24
|
-
solr_doc.merge!(SOLR_DOCUMENT_ID.to_sym => pid)
|
25
|
-
solrize_profile(solr_doc)
|
26
|
-
end
|
27
|
-
datastreams.each_value do |ds|
|
28
|
-
solr_doc.merge! ds.to_solr()
|
29
|
-
end
|
30
|
-
solr_doc = solrize_relationships(solr_doc) unless opts[:model_only]
|
31
|
-
solr_doc
|
10
|
+
indexing_service.generate_solr_document
|
32
11
|
end
|
33
12
|
|
34
|
-
def
|
35
|
-
|
13
|
+
def indexing_service
|
14
|
+
@indexing_service ||= self.class.indexer.new(self)
|
36
15
|
end
|
37
16
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
inner_object.profile.each_pair do |property,value|
|
42
|
-
if property =~ /Date/
|
43
|
-
value = Time.parse(value) unless value.is_a?(Time)
|
44
|
-
value = value.xmlschema
|
45
|
-
end
|
46
|
-
profile_hash[property] = value
|
47
|
-
end
|
48
|
-
end
|
49
|
-
self.datastreams.each_pair { |dsid,ds| profile_hash['datastreams'][dsid] = ds.solrize_profile }
|
50
|
-
solr_doc[self.class.profile_solr_name] = profile_hash.to_json
|
17
|
+
# Updates Solr index with self.
|
18
|
+
def update_index
|
19
|
+
SolrService.add(to_solr, softCommit: true)
|
51
20
|
end
|
52
21
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
val = literal ? statement.object.value : statement.object.to_str
|
60
|
-
::Solrizer::Extractor.insert_solr_field_value(solr_doc, solr_name(predicate, :symbol), val )
|
22
|
+
protected
|
23
|
+
|
24
|
+
# Determines whether a create operation causes a solr index of this object by default.
|
25
|
+
# Override this if you need different behavior.
|
26
|
+
def create_needs_index?
|
27
|
+
ENABLE_SOLR_UPDATES
|
61
28
|
end
|
62
|
-
return solr_doc
|
63
|
-
end
|
64
29
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
solrizer = Solrizer::Fedora::Solrizer.new
|
70
|
-
solrizer.solrize( self )
|
71
|
-
else
|
72
|
-
SolrService.add(self.to_solr, softCommit: true)
|
30
|
+
# Determines whether an update operation causes a solr index of this object by default.
|
31
|
+
# Override this if you need different behavior
|
32
|
+
def update_needs_index?
|
33
|
+
ENABLE_SOLR_UPDATES
|
73
34
|
end
|
74
|
-
end
|
75
35
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
36
|
+
private
|
37
|
+
|
38
|
+
# index the record after it has been persisted to Fedora
|
39
|
+
def create_record(options = {})
|
40
|
+
super
|
41
|
+
update_index if create_needs_index? && options.fetch(:update_index, true)
|
42
|
+
true
|
43
|
+
end
|
44
|
+
|
45
|
+
# index the record after it has been updated in Fedora
|
46
|
+
def update_record(options = {})
|
47
|
+
super
|
48
|
+
update_index if update_needs_index? && options.fetch(:update_index, true)
|
49
|
+
true
|
50
|
+
end
|
80
51
|
|
81
52
|
module ClassMethods
|
53
|
+
|
54
|
+
def indexer
|
55
|
+
IndexingService
|
56
|
+
end
|
57
|
+
|
58
|
+
def reindex_everything
|
59
|
+
get_descendent_uris(ActiveFedora::Base.id_to_uri('')).each do |uri|
|
60
|
+
logger.debug "Re-index everything ... #{uri}"
|
61
|
+
ActiveFedora::Base.find(LdpResource.new(ActiveFedora.fedora.connection, uri)).update_index
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
82
65
|
# This method can be used instead of ActiveFedora::Model::ClassMethods.find.
|
83
66
|
# It works similarly except it populates an object from Solr instead of Fedora.
|
84
67
|
# It is most useful for objects used in read-only displays in order to speed up loading time. If only
|
85
|
-
# a
|
68
|
+
# a id is passed in it will query solr for a corresponding solr document and then use it
|
86
69
|
# to populate this object.
|
87
70
|
#
|
88
71
|
# If a value is passed in for optional parameter solr_doc it will not query solr again and just use the
|
89
72
|
# one passed to populate the object.
|
90
73
|
#
|
91
|
-
# It will anything stored within solr such as metadata and relationships. Non-metadata
|
74
|
+
# It will anything stored within solr such as metadata and relationships. Non-metadata attached files will not
|
92
75
|
# be loaded and if needed you should use find instead.
|
93
|
-
def load_instance_from_solr(
|
94
|
-
SolrInstanceLoader.new(self,
|
76
|
+
def load_instance_from_solr(id, solr_doc=nil)
|
77
|
+
SolrInstanceLoader.new(self, id, solr_doc).object
|
95
78
|
end
|
96
79
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
next if object.pid.start_with?('fedora-system:')
|
104
|
-
ActiveFedora::Base.find(object.pid).update_index
|
105
|
-
end
|
80
|
+
def get_descendent_uris(uri)
|
81
|
+
resource = Ldp::Resource::RdfSource.new(ActiveFedora.fedora.connection, uri)
|
82
|
+
immediate_descendent_uris = resource.graph.query(predicate: ::RDF::LDP.contains).map { |descendent| descendent.object.to_s }
|
83
|
+
all_descendents_uris = [uri]
|
84
|
+
immediate_descendent_uris.each do |descendent_uri|
|
85
|
+
all_descendents_uris += get_descendent_uris(descendent_uri)
|
106
86
|
end
|
87
|
+
all_descendents_uris
|
107
88
|
end
|
108
89
|
|
109
|
-
private
|
110
|
-
|
111
|
-
def connections
|
112
|
-
if ActiveFedora.config.sharded?
|
113
|
-
return ActiveFedora.config.credentials.map { |cred| ActiveFedora::RubydoraConnection.new(cred).connection}
|
114
|
-
else
|
115
|
-
return [ActiveFedora::RubydoraConnection.new(ActiveFedora.config.credentials).connection]
|
116
|
-
end
|
117
|
-
end
|
118
90
|
end
|
91
|
+
|
119
92
|
end
|
120
93
|
end
|