active-fedora 10.0.0 → 11.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/.gitignore +1 -0
- data/.rubocop.yml +6 -7
- data/.rubocop_todo.yml +55 -0
- data/.solr_wrapper +6 -0
- data/README.md +1 -3
- data/active-fedora.gemspec +6 -11
- 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 +3 -3
- data/lib/active_fedora/associations/contained_finder.rb +2 -2
- 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/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/containers/container.rb +1 -1
- data/lib/active_fedora/core.rb +22 -25
- data/lib/active_fedora/fedora_attributes.rb +1 -1
- data/lib/active_fedora/file/streaming.rb +1 -1
- data/lib/active_fedora/file.rb +1 -9
- data/lib/active_fedora/indexing.rb +0 -15
- data/lib/active_fedora/indexing_service.rb +0 -9
- data/lib/active_fedora/loadable_from_json.rb +12 -1
- data/lib/active_fedora/nested_attributes.rb +2 -2
- data/lib/active_fedora/orders/list_node.rb +2 -2
- data/lib/active_fedora/orders/ordered_list.rb +7 -3
- 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/persistence.rb +1 -0
- data/lib/active_fedora/rdf.rb +0 -2
- data/lib/active_fedora/relation/delegation.rb +4 -0
- data/lib/active_fedora/relation/finder_methods.rb +3 -3
- data/lib/active_fedora/scoping/named.rb +1 -0
- data/lib/active_fedora/solr_hit.rb +0 -13
- data/lib/active_fedora/solr_query_builder.rb +24 -13
- data/lib/active_fedora/version.rb +1 -1
- data/lib/active_fedora.rb +0 -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 -9
- data/spec/config_helper.rb +1 -1
- data/spec/integration/associations_spec.rb +23 -24
- data/spec/integration/attached_files_spec.rb +18 -8
- data/spec/integration/attributes_spec.rb +12 -16
- data/spec/integration/autosave_association_spec.rb +6 -6
- data/spec/integration/base_spec.rb +3 -3
- 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 -16
- 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 +32 -34
- data/spec/integration/generators/solr_generator_spec.rb +7 -10
- data/spec/integration/has_and_belongs_to_many_associations_spec.rb +5 -5
- 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 +4 -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 -4
- 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 +16 -22
- 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_spec.rb +62 -26
- 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 +1 -1
- data/spec/unit/file_spec.rb +61 -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 +5 -5
- 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 +6 -6
- 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 -146
- 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 +20 -20
- 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 +9 -9
- 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 +18 -122
- 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 -67
- data/lib/active_fedora/om_datastream.rb +0 -126
- 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 -43
- data/lib/active_fedora/rdf/ntriples_rdf_datastream.rb +0 -9
- data/lib/active_fedora/rdf/rdf_datastream.rb +0 -158
- 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 -155
- 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 -325
- 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
|
@@ -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
|
|
@@ -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)
|
|
@@ -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
|
@@ -255,13 +255,13 @@ module ActiveFedora
|
|
|
255
255
|
# @param [Hash<Symbol,String>] conditions
|
|
256
256
|
# @return [Array<String>]
|
|
257
257
|
def create_query_from_hash(conditions)
|
|
258
|
-
conditions.map { |key, value| condition_to_clauses(key, value) }.compact
|
|
258
|
+
conditions.map { |key, value| condition_to_clauses(key, value, ' OR ') }.compact
|
|
259
259
|
end
|
|
260
260
|
|
|
261
261
|
# @param [Symbol] key
|
|
262
262
|
# @param [String] value
|
|
263
|
-
def condition_to_clauses(key, value)
|
|
264
|
-
SolrQueryBuilder.construct_query([[field_name_for(key), value]])
|
|
263
|
+
def condition_to_clauses(key, value, join_with = SolrQueryBuilder.default_join_with)
|
|
264
|
+
SolrQueryBuilder.construct_query([[field_name_for(key), value]], join_with)
|
|
265
265
|
end
|
|
266
266
|
|
|
267
267
|
# If the key is a property name, turn it into a solr field
|
|
@@ -13,6 +13,7 @@ module ActiveFedora
|
|
|
13
13
|
#
|
|
14
14
|
# fruits = Fruit.all
|
|
15
15
|
# fruits = fruits.where(color: 'red') if options[:red_only]
|
|
16
|
+
# fruits = fruits.where(size: ['big', 'little']) # gets big or little fruit
|
|
16
17
|
# fruits = fruits.limit(10) if limited?
|
|
17
18
|
#
|
|
18
19
|
# You can define a scope that applies to all finders using
|
|
@@ -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,49 +11,59 @@ 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
|
-
def construct_query_for_rel(field_pairs, join_with =
|
|
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 =
|
|
35
|
-
pairs_to_clauses(field_pairs)
|
|
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?
|
|
38
|
+
return clauses.first if clauses.count == 1
|
|
39
|
+
"(#{clauses.join(join_with)})"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def default_join_with
|
|
43
|
+
' AND '
|
|
36
44
|
end
|
|
37
45
|
|
|
38
46
|
private
|
|
39
47
|
|
|
40
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'
|
|
41
50
|
# @return [Array] a list of solr clauses
|
|
42
|
-
def pairs_to_clauses(pairs)
|
|
51
|
+
def pairs_to_clauses(pairs, type)
|
|
43
52
|
pairs.flat_map do |field, value|
|
|
44
|
-
condition_to_clauses(field, value)
|
|
53
|
+
condition_to_clauses(field, value, type)
|
|
45
54
|
end
|
|
46
55
|
end
|
|
47
56
|
|
|
48
57
|
# @param [String] field
|
|
49
58
|
# @param [String, Array<String>] values
|
|
59
|
+
# @param [String] type The type of query to run. Either 'raw' or 'field'
|
|
50
60
|
# @return [Array<String>]
|
|
51
|
-
def condition_to_clauses(field, values)
|
|
61
|
+
def condition_to_clauses(field, values, type)
|
|
52
62
|
values = Array(values)
|
|
53
63
|
values << nil if values.empty?
|
|
54
64
|
values.map do |value|
|
|
55
65
|
if value.present?
|
|
56
|
-
|
|
66
|
+
query_clause(type, field, value)
|
|
57
67
|
else
|
|
58
68
|
# Check that the field is not present. In SQL: "WHERE field IS NULL"
|
|
59
69
|
"-#{field}:[* TO *]"
|
|
@@ -86,10 +96,11 @@ module ActiveFedora
|
|
|
86
96
|
end
|
|
87
97
|
|
|
88
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'
|
|
89
100
|
# @param [String] key
|
|
90
101
|
# @param [String] value
|
|
91
|
-
def
|
|
92
|
-
"_query_:\"{
|
|
102
|
+
def query_clause(type, key, value)
|
|
103
|
+
"_query_:\"{!#{type} f=#{key}}#{value.gsub('"', '\"')}\""
|
|
93
104
|
end
|
|
94
105
|
end
|
|
95
106
|
end
|
data/lib/active_fedora.rb
CHANGED
|
@@ -59,7 +59,6 @@ module ActiveFedora #:nodoc:
|
|
|
59
59
|
autoload :DirectContainer
|
|
60
60
|
autoload :IndirectContainer
|
|
61
61
|
end
|
|
62
|
-
autoload :Datastreams
|
|
63
62
|
autoload :DelegatedAttribute
|
|
64
63
|
autoload_under 'attributes' do
|
|
65
64
|
autoload :ActiveTripleAttribute
|
|
@@ -89,24 +88,14 @@ module ActiveFedora #:nodoc:
|
|
|
89
88
|
autoload :LoadableFromJson
|
|
90
89
|
autoload :ModelClassifier
|
|
91
90
|
autoload :NestedAttributes
|
|
92
|
-
autoload :NomDatastream
|
|
93
91
|
autoload :NullRelation
|
|
94
|
-
autoload :OmDatastream
|
|
95
92
|
autoload :Orders
|
|
96
93
|
autoload :Pathing
|
|
97
94
|
autoload :Persistence
|
|
98
|
-
autoload :ProfileIndexingService
|
|
99
95
|
autoload :Property
|
|
100
|
-
autoload :QualifiedDublinCoreDatastream
|
|
101
96
|
autoload :Querying
|
|
102
97
|
autoload :QueryResultBuilder
|
|
103
98
|
autoload :RDF
|
|
104
|
-
autoload_under 'rdf' do
|
|
105
|
-
autoload :RDFDatastream
|
|
106
|
-
autoload :RDFXMLDatastream
|
|
107
|
-
autoload :NtriplesRDFDatastream
|
|
108
|
-
autoload :FedoraRdfResource
|
|
109
|
-
end
|
|
110
99
|
autoload :Reflection
|
|
111
100
|
autoload :Relation
|
|
112
101
|
|
|
@@ -124,7 +113,6 @@ module ActiveFedora #:nodoc:
|
|
|
124
113
|
autoload :Serialization
|
|
125
114
|
autoload :SchemaIndexingStrategy
|
|
126
115
|
autoload :SolrHit
|
|
127
|
-
autoload :SolrInstanceLoader
|
|
128
116
|
autoload :SolrQueryBuilder
|
|
129
117
|
autoload :SolrService
|
|
130
118
|
autoload :SparqlInsert
|
|
@@ -187,6 +187,17 @@
|
|
|
187
187
|
</lst>
|
|
188
188
|
</requestHandler>
|
|
189
189
|
|
|
190
|
+
<searchComponent name="termsComponent" class="solr.TermsComponent" />
|
|
191
|
+
|
|
192
|
+
<requestHandler name="/terms" class="solr.SearchHandler">
|
|
193
|
+
<lst name="defaults">
|
|
194
|
+
<bool name="terms">true</bool>
|
|
195
|
+
</lst>
|
|
196
|
+
<arr name="components">
|
|
197
|
+
<str>termsComponent</str>
|
|
198
|
+
</arr>
|
|
199
|
+
</requestHandler>
|
|
200
|
+
|
|
190
201
|
<!-- Spell Check
|
|
191
202
|
|
|
192
203
|
The spell check component can return a list of alternative spelling
|
|
@@ -7,7 +7,7 @@ module ActiveFedora
|
|
|
7
7
|
|
|
8
8
|
class_option :directory, type: :string, default: 'models', desc: "Which directory to generate? (i.e. app/DIRECTORY)"
|
|
9
9
|
class_option :datastream_directory, type: :string, default: 'models/datastreams', desc: "Which datastream directory to generate? (i.e. models/datastreams)"
|
|
10
|
-
class_option :
|
|
10
|
+
class_option :has_subresource, type: :string, default: nil, desc: "Name a file to attach"
|
|
11
11
|
class_option :datastream, type: :string, default: nil, desc: "Name a metadata datastream to create"
|
|
12
12
|
|
|
13
13
|
def install
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# `rails generate active_fedora:model <%= class_name %>`
|
|
3
3
|
class <%= class_name %> < ActiveFedora::Base
|
|
4
4
|
<% if options['datastream'] %>
|
|
5
|
-
|
|
5
|
+
has_subresource :descMetadata, class_name: "<%= options['datastream'] %>"
|
|
6
6
|
<% else %>
|
|
7
7
|
# Define some properties to store:
|
|
8
8
|
#
|
|
@@ -19,12 +19,12 @@ class <%= class_name %> < ActiveFedora::Base
|
|
|
19
19
|
index.as :stored_searchable
|
|
20
20
|
end
|
|
21
21
|
<%- end -%>
|
|
22
|
-
<% if options['
|
|
23
|
-
|
|
22
|
+
<% if options['has_subresource'] %>
|
|
23
|
+
has_subresource :<%= options['has_subresource'] %>"
|
|
24
24
|
<% else %>
|
|
25
25
|
# Uncomment the following lines to add an #attachment method that is a file
|
|
26
26
|
#
|
|
27
|
-
#
|
|
27
|
+
# has_subresource "attachment"
|
|
28
28
|
<% end %>
|
|
29
29
|
#
|
|
30
30
|
# If you need to add additional attributes to the SOLR document, extend the default indexer:
|
|
@@ -41,19 +41,11 @@ namespace :active_fedora do
|
|
|
41
41
|
spec.rcov = true
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
-
desc "Copies the default SOLR config for the bundled Testing Server"
|
|
45
|
-
task :configure_jetty do
|
|
46
|
-
FileList['lib/generators/active_fedora/config/solr/templates/solr_conf/conf/*'].each do |f|
|
|
47
|
-
cp("#{f}", 'jetty/solr/development-core/conf/', :verbose => true)
|
|
48
|
-
cp("#{f}", 'jetty/solr/test-core/conf/', :verbose => true)
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
44
|
desc "CI build"
|
|
53
45
|
task :ci do
|
|
46
|
+
Rake::Task['active_fedora:rubocop'].invoke unless ENV['NO_RUBOCOP']
|
|
54
47
|
ENV['environment'] = "test"
|
|
55
48
|
with_test_server do
|
|
56
|
-
Rake::Task['active_fedora:rubocop'].invoke unless ENV['NO_RUBOCOP']
|
|
57
49
|
Rake::Task['active_fedora:coverage'].invoke
|
|
58
50
|
end
|
|
59
51
|
end
|
data/spec/config_helper.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
def mock_yaml(hash, path)
|
|
2
|
-
mock_file =
|
|
2
|
+
mock_file = instance_double(File, path.split("/")[-1])
|
|
3
3
|
allow(File).to receive(:exist?).with(path).and_return(true)
|
|
4
4
|
allow(File).to receive(:open).with(path).and_return(mock_file)
|
|
5
5
|
allow(Psych).to receive(:load).and_return(hash)
|
|
@@ -17,7 +17,7 @@ describe ActiveFedora::Base do
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
let(:person) { Person.create }
|
|
20
|
-
|
|
20
|
+
subject(:book) { Book.new(author: person) }
|
|
21
21
|
|
|
22
22
|
it "goes" do
|
|
23
23
|
book.save
|
|
@@ -197,7 +197,7 @@ describe ActiveFedora::Base do
|
|
|
197
197
|
|
|
198
198
|
it "lets you set an array of objects" do
|
|
199
199
|
@library.books = [@book, @book2]
|
|
200
|
-
expect(@library.books).to
|
|
200
|
+
expect(@library.books).to contain_exactly @book, @book2
|
|
201
201
|
@library.save
|
|
202
202
|
|
|
203
203
|
@library.books = [@book]
|
|
@@ -205,7 +205,7 @@ describe ActiveFedora::Base do
|
|
|
205
205
|
end
|
|
206
206
|
it "lets you set an array of object ids" do
|
|
207
207
|
@library.book_ids = [@book.id, @book2.id]
|
|
208
|
-
expect(@library.books).to
|
|
208
|
+
expect(@library.books).to contain_exactly @book, @book2
|
|
209
209
|
end
|
|
210
210
|
|
|
211
211
|
it "setter should wipe out previously saved relations" do
|
|
@@ -219,7 +219,7 @@ describe ActiveFedora::Base do
|
|
|
219
219
|
@library.books = [@book, @book2]
|
|
220
220
|
@library.save
|
|
221
221
|
@library = Library.find(@library.id)
|
|
222
|
-
expect(@library.books).to
|
|
222
|
+
expect(@library.books).to contain_exactly @book, @book2
|
|
223
223
|
end
|
|
224
224
|
|
|
225
225
|
it "lets you lookup an array of objects with solr" do
|
|
@@ -230,7 +230,7 @@ describe ActiveFedora::Base do
|
|
|
230
230
|
@book2.save
|
|
231
231
|
|
|
232
232
|
@library = Library.find(@library.id)
|
|
233
|
-
expect(@library.books).to
|
|
233
|
+
expect(@library.books).to contain_exactly @book, @book2
|
|
234
234
|
|
|
235
235
|
solr_resp = @library.books(response_format: :solr)
|
|
236
236
|
expect(solr_resp.size).to eq 2
|
|
@@ -462,7 +462,7 @@ describe ActiveFedora::Base do
|
|
|
462
462
|
|
|
463
463
|
it "loads the association stored in the parent" do
|
|
464
464
|
@reloaded_course = Course.find(@course.id)
|
|
465
|
-
expect(@reloaded_course.textbooks).to
|
|
465
|
+
expect(@reloaded_course.textbooks).to contain_exactly @t1, @t2
|
|
466
466
|
end
|
|
467
467
|
|
|
468
468
|
it "allows a parent to be deleted from the has_many association" do
|
|
@@ -480,7 +480,7 @@ describe ActiveFedora::Base do
|
|
|
480
480
|
@course.textbooks = [@t3, @t4]
|
|
481
481
|
@course.save
|
|
482
482
|
|
|
483
|
-
expect(@course.reload.textbooks).to
|
|
483
|
+
expect(@course.reload.textbooks).to contain_exactly @t3, @t4
|
|
484
484
|
end
|
|
485
485
|
|
|
486
486
|
it "allows a child to be deleted from the has_and_belongs_to_many association" do
|
|
@@ -524,18 +524,19 @@ describe ActiveFedora::Base do
|
|
|
524
524
|
end
|
|
525
525
|
|
|
526
526
|
describe "removing association" do
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
527
|
+
let(:p1) { Page.create }
|
|
528
|
+
let(:p2) { Page.create }
|
|
529
|
+
subject(:book) do
|
|
530
|
+
book = LibraryBook.create
|
|
531
|
+
book.pages << p1 << p2
|
|
532
|
+
book.save!
|
|
533
|
+
book
|
|
533
534
|
end
|
|
534
535
|
it "saves between the before and after hooks" do
|
|
535
|
-
expect(
|
|
536
|
-
expect(
|
|
537
|
-
expect(
|
|
538
|
-
|
|
536
|
+
expect(book).to receive(:before_count).with(1)
|
|
537
|
+
expect(book).to receive(:after_count).with(0)
|
|
538
|
+
expect(book).to receive(:say_hi).with(p2).twice
|
|
539
|
+
book.pages.delete(p2)
|
|
539
540
|
end
|
|
540
541
|
end
|
|
541
542
|
end
|
|
@@ -555,14 +556,12 @@ describe ActiveFedora::Base do
|
|
|
555
556
|
end
|
|
556
557
|
|
|
557
558
|
describe "removing association" do
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
@p2 = subject.pages.build
|
|
562
|
-
end
|
|
559
|
+
let(:p1) { book.pages.build }
|
|
560
|
+
let(:p2) { book.pages.build }
|
|
561
|
+
let(:book) { LibraryBook.new }
|
|
563
562
|
it "runs the hooks" do
|
|
564
|
-
expect(
|
|
565
|
-
|
|
563
|
+
expect(book).to receive(:say_hi).with(p2)
|
|
564
|
+
book.pages.delete(p2)
|
|
566
565
|
end
|
|
567
566
|
end
|
|
568
567
|
end
|
|
@@ -65,30 +65,40 @@ describe ActiveFedora::AttachedFiles do
|
|
|
65
65
|
let(:obj) { ActiveFedora::Base.new }
|
|
66
66
|
|
|
67
67
|
describe ".attached_files" do
|
|
68
|
-
subject { obj.attached_files }
|
|
68
|
+
subject(:attached_files) { obj.attached_files }
|
|
69
69
|
it "returns a Hash of datastreams from fedora" do
|
|
70
|
-
expect(
|
|
71
|
-
expect(
|
|
70
|
+
expect(attached_files).to be_a_kind_of(ActiveFedora::FilesHash)
|
|
71
|
+
expect(attached_files).to be_empty
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
it "initializes the datastream pointers with @new_object=false" do
|
|
75
|
-
|
|
75
|
+
attached_files.each_value do |ds|
|
|
76
76
|
expect(ds).to_not be_new
|
|
77
77
|
end
|
|
78
78
|
end
|
|
79
79
|
end
|
|
80
80
|
|
|
81
81
|
describe ".metadata_streams" do
|
|
82
|
-
let(:mds1) { ActiveFedora::QualifiedDublinCoreDatastream.new }
|
|
83
|
-
let(:mds2) { ActiveFedora::QualifiedDublinCoreDatastream.new }
|
|
84
|
-
let(:fds) { ActiveFedora::File.new }
|
|
85
82
|
before do
|
|
86
|
-
|
|
83
|
+
class Metadata < ActiveFedora::File
|
|
84
|
+
def metadata?
|
|
85
|
+
true
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
87
89
|
obj.attach_file(mds1, 'md1')
|
|
88
90
|
obj.attach_file(mds2, 'qdc')
|
|
89
91
|
obj.attach_file(fds, 'fds')
|
|
90
92
|
end
|
|
91
93
|
|
|
94
|
+
let(:mds1) { Metadata.new }
|
|
95
|
+
let(:mds2) { Metadata.new }
|
|
96
|
+
let(:fds) { ActiveFedora::File.new }
|
|
97
|
+
|
|
98
|
+
after do
|
|
99
|
+
Object.send(:remove_const, :Metadata)
|
|
100
|
+
end
|
|
101
|
+
|
|
92
102
|
it "returns all of the datastreams from the object that are kinds of OmDatastream" do
|
|
93
103
|
expect(obj.metadata_streams).to match_array [mds1, mds2]
|
|
94
104
|
end
|