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.
Files changed (189) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +6 -7
  4. data/.rubocop_todo.yml +55 -0
  5. data/.solr_wrapper +6 -0
  6. data/README.md +1 -3
  7. data/active-fedora.gemspec +6 -11
  8. data/lib/active_fedora/aggregation/list_source.rb +2 -0
  9. data/lib/active_fedora/associations/association_scope.rb +1 -1
  10. data/lib/active_fedora/associations/builder/aggregation.rb +1 -1
  11. data/lib/active_fedora/associations/builder/association.rb +1 -1
  12. data/lib/active_fedora/associations/builder/orders.rb +11 -3
  13. data/lib/active_fedora/associations/collection_association.rb +3 -3
  14. data/lib/active_fedora/associations/contained_finder.rb +2 -2
  15. data/lib/active_fedora/associations/has_many_association.rb +2 -2
  16. data/lib/active_fedora/associations/has_subresource_association.rb +2 -2
  17. data/lib/active_fedora/associations/orders_association.rb +4 -0
  18. data/lib/active_fedora/associations/rdf.rb +2 -0
  19. data/lib/active_fedora/attribute_assignment.rb +0 -1
  20. data/lib/active_fedora/attribute_methods/dirty.rb +1 -1
  21. data/lib/active_fedora/attributes.rb +1 -1
  22. data/lib/active_fedora/base.rb +4 -8
  23. data/lib/active_fedora/change_set.rb +6 -2
  24. data/lib/active_fedora/containers/container.rb +1 -1
  25. data/lib/active_fedora/core.rb +22 -25
  26. data/lib/active_fedora/fedora_attributes.rb +1 -1
  27. data/lib/active_fedora/file/streaming.rb +1 -1
  28. data/lib/active_fedora/file.rb +1 -9
  29. data/lib/active_fedora/indexing.rb +0 -15
  30. data/lib/active_fedora/indexing_service.rb +0 -9
  31. data/lib/active_fedora/loadable_from_json.rb +12 -1
  32. data/lib/active_fedora/nested_attributes.rb +2 -2
  33. data/lib/active_fedora/orders/list_node.rb +2 -2
  34. data/lib/active_fedora/orders/ordered_list.rb +7 -3
  35. data/lib/active_fedora/orders/target_proxy.rb +4 -0
  36. data/lib/active_fedora/querying.rb +1 -1
  37. data/lib/active_fedora/railtie.rb +2 -2
  38. data/lib/active_fedora/rake_support.rb +1 -1
  39. data/lib/active_fedora/rdf/persistence.rb +1 -0
  40. data/lib/active_fedora/rdf.rb +0 -2
  41. data/lib/active_fedora/relation/delegation.rb +4 -0
  42. data/lib/active_fedora/relation/finder_methods.rb +3 -3
  43. data/lib/active_fedora/scoping/named.rb +1 -0
  44. data/lib/active_fedora/solr_hit.rb +0 -13
  45. data/lib/active_fedora/solr_query_builder.rb +24 -13
  46. data/lib/active_fedora/version.rb +1 -1
  47. data/lib/active_fedora.rb +0 -12
  48. data/lib/generators/active_fedora/config/solr/templates/solr/config/solrconfig.xml +11 -0
  49. data/lib/generators/active_fedora/config/solr/templates/solr_wrapper_test.yml +1 -1
  50. data/lib/generators/active_fedora/model/model_generator.rb +1 -1
  51. data/lib/generators/active_fedora/model/templates/model.rb.erb +4 -4
  52. data/lib/tasks/active_fedora_dev.rake +1 -9
  53. data/spec/config_helper.rb +1 -1
  54. data/spec/integration/associations_spec.rb +23 -24
  55. data/spec/integration/attached_files_spec.rb +18 -8
  56. data/spec/integration/attributes_spec.rb +12 -16
  57. data/spec/integration/autosave_association_spec.rb +6 -6
  58. data/spec/integration/base_spec.rb +3 -3
  59. data/spec/integration/basic_contains_association_spec.rb +1 -1
  60. data/spec/integration/clean_connection_spec.rb +1 -1
  61. data/spec/integration/collection_association_spec.rb +2 -5
  62. data/spec/integration/date_time_properties_spec.rb +1 -16
  63. data/spec/integration/direct_container_spec.rb +12 -12
  64. data/spec/integration/directly_contains_one_association_spec.rb +11 -13
  65. data/spec/integration/eradicate_spec.rb +1 -1
  66. data/spec/integration/fedora_solr_sync_spec.rb +2 -2
  67. data/spec/integration/file_fixity_spec.rb +6 -8
  68. data/spec/integration/file_spec.rb +32 -34
  69. data/spec/integration/generators/solr_generator_spec.rb +7 -10
  70. data/spec/integration/has_and_belongs_to_many_associations_spec.rb +5 -5
  71. data/spec/integration/has_many_associations_spec.rb +9 -11
  72. data/spec/integration/indexing_spec.rb +2 -2
  73. data/spec/integration/indirect_container_spec.rb +11 -12
  74. data/spec/integration/json_serialization_spec.rb +4 -4
  75. data/spec/integration/query_result_builder_spec.rb +9 -21
  76. data/spec/integration/rdf_nested_attributes_spec.rb +7 -7
  77. data/spec/integration/relation_delegation_spec.rb +8 -10
  78. data/spec/integration/relation_spec.rb +13 -16
  79. data/spec/integration/scoped_query_spec.rb +4 -3
  80. data/spec/integration/solr_hit_spec.rb +4 -15
  81. data/spec/integration/versionable_spec.rb +73 -327
  82. data/spec/integration/with_metadata_spec.rb +1 -1
  83. data/spec/spec_helper.rb +52 -4
  84. data/spec/unit/active_fedora_spec.rb +1 -1
  85. data/spec/unit/aggregation/list_source_spec.rb +37 -37
  86. data/spec/unit/aggregation/ordered_reader_spec.rb +4 -4
  87. data/spec/unit/association_hash_spec.rb +17 -31
  88. data/spec/unit/attached_files_spec.rb +35 -32
  89. data/spec/unit/attributes_spec.rb +25 -25
  90. data/spec/unit/base_active_model_spec.rb +8 -8
  91. data/spec/unit/base_cma_spec.rb +1 -1
  92. data/spec/unit/base_extra_spec.rb +7 -22
  93. data/spec/unit/base_spec.rb +16 -22
  94. data/spec/unit/callback_spec.rb +2 -2
  95. data/spec/unit/change_set_spec.rb +5 -5
  96. data/spec/unit/checksum_spec.rb +2 -2
  97. data/spec/unit/code_configurator_spec.rb +1 -1
  98. data/spec/unit/core_spec.rb +62 -26
  99. data/spec/unit/default_model_mapper_spec.rb +6 -6
  100. data/spec/unit/fedora_spec.rb +3 -4
  101. data/spec/unit/file_configurator_spec.rb +96 -96
  102. data/spec/unit/file_path_builder_spec.rb +1 -1
  103. data/spec/unit/file_spec.rb +61 -61
  104. data/spec/unit/files_hash_spec.rb +9 -9
  105. data/spec/unit/filter_spec.rb +3 -3
  106. data/spec/unit/finder_methods_spec.rb +5 -5
  107. data/spec/unit/forbidden_attributes_protection_spec.rb +2 -2
  108. data/spec/unit/has_and_belongs_to_many_association_spec.rb +14 -15
  109. data/spec/unit/has_many_association_spec.rb +28 -13
  110. data/spec/unit/indexers/global_indexer_spec.rb +6 -6
  111. data/spec/unit/indexing_service_spec.rb +5 -5
  112. data/spec/unit/indexing_spec.rb +6 -6
  113. data/spec/unit/inheritance_spec.rb +11 -7
  114. data/spec/unit/loadable_from_json_spec.rb +4 -4
  115. data/spec/unit/logger_spec.rb +1 -1
  116. data/spec/unit/model_classifier_spec.rb +5 -5
  117. data/spec/unit/ordered_spec.rb +144 -146
  118. data/spec/unit/orders/list_node_spec.rb +22 -22
  119. data/spec/unit/orders/ordered_list_spec.rb +96 -96
  120. data/spec/unit/orders/reflection_spec.rb +4 -4
  121. data/spec/unit/pathing_spec.rb +4 -4
  122. data/spec/unit/persistence_spec.rb +28 -28
  123. data/spec/unit/property_spec.rb +2 -2
  124. data/spec/unit/query_spec.rb +20 -20
  125. data/spec/unit/rdf/indexing_service_spec.rb +29 -29
  126. data/spec/unit/readonly_spec.rb +5 -4
  127. data/spec/unit/reflection_spec.rb +3 -3
  128. data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +9 -9
  129. data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +9 -9
  130. data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +9 -9
  131. data/spec/unit/schema_indexing_strategy_spec.rb +5 -5
  132. data/spec/unit/serializers_spec.rb +3 -4
  133. data/spec/unit/solr_config_options_spec.rb +13 -16
  134. data/spec/unit/solr_hit_spec.rb +9 -9
  135. data/spec/unit/solr_service_spec.rb +4 -10
  136. data/spec/unit/sparql_insert_spec.rb +2 -2
  137. data/spec/unit/validations_spec.rb +9 -9
  138. data/spec/unit/with_metadata/default_metadata_class_factory_spec.rb +3 -2
  139. data/spec/unit/with_metadata/metadata_node_spec.rb +3 -2
  140. metadata +18 -122
  141. data/lib/active_fedora/datastreams/nokogiri_datastreams.rb +0 -119
  142. data/lib/active_fedora/datastreams.rb +0 -6
  143. data/lib/active_fedora/nom_datastream.rb +0 -67
  144. data/lib/active_fedora/om_datastream.rb +0 -126
  145. data/lib/active_fedora/profile_indexing_service.rb +0 -11
  146. data/lib/active_fedora/qualified_dublin_core_datastream.rb +0 -158
  147. data/lib/active_fedora/rdf/datastream_indexing.rb +0 -43
  148. data/lib/active_fedora/rdf/ntriples_rdf_datastream.rb +0 -9
  149. data/lib/active_fedora/rdf/rdf_datastream.rb +0 -158
  150. data/lib/active_fedora/rdf/rdfxml_datastream.rb +0 -13
  151. data/lib/active_fedora/solr_instance_loader.rb +0 -47
  152. data/solr/config/_rest_managed.json +0 -3
  153. data/solr/config/admin-extra.html +0 -31
  154. data/solr/config/elevate.xml +0 -36
  155. data/solr/config/mapping-ISOLatin1Accent.txt +0 -246
  156. data/solr/config/protwords.txt +0 -21
  157. data/solr/config/schema.xml +0 -372
  158. data/solr/config/scripts.conf +0 -24
  159. data/solr/config/solrconfig.xml +0 -311
  160. data/solr/config/spellings.txt +0 -2
  161. data/solr/config/stopwords.txt +0 -58
  162. data/solr/config/stopwords_en.txt +0 -58
  163. data/solr/config/synonyms.txt +0 -31
  164. data/solr/config/xslt/example.xsl +0 -132
  165. data/solr/config/xslt/example_atom.xsl +0 -67
  166. data/solr/config/xslt/example_rss.xsl +0 -66
  167. data/solr/config/xslt/luke.xsl +0 -337
  168. data/spec/fixtures/damsObjectModel.xml +0 -38
  169. data/spec/fixtures/dublin_core_rdf_descMetadata.nt +0 -13
  170. data/spec/fixtures/mixed_rdf_descMetadata.nt +0 -7
  171. data/spec/fixtures/mods_articles/mods_article1.xml +0 -98
  172. data/spec/fixtures/solr_rdf_descMetadata.nt +0 -7
  173. data/spec/integration/complex_rdf_datastream_spec.rb +0 -228
  174. data/spec/integration/datastream_rdf_nested_attributes_spec.rb +0 -179
  175. data/spec/integration/ntriples_datastream_spec.rb +0 -203
  176. data/spec/integration/om_datastream_spec.rb +0 -78
  177. data/spec/integration/solr_instance_loader_spec.rb +0 -155
  178. data/spec/samples/hydra-mods_article_datastream.rb +0 -517
  179. data/spec/samples/models/mods_article.rb +0 -9
  180. data/spec/samples/oral_history_sample.xml +0 -38
  181. data/spec/samples/oral_history_xml.xml +0 -35
  182. data/spec/samples/samples.rb +0 -2
  183. data/spec/unit/nom_datastream_spec.rb +0 -60
  184. data/spec/unit/ntriples_datastream_spec.rb +0 -170
  185. data/spec/unit/om_datastream_spec.rb +0 -325
  186. data/spec/unit/qualified_dublin_core_datastream_spec.rb +0 -119
  187. data/spec/unit/rdf_datastream_spec.rb +0 -84
  188. data/spec/unit/rdf_resource_datastream_spec.rb +0 -204
  189. 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 = self.class.reflect_on_property(attribute_name)
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( id _destroy ).freeze
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 == 0 ? send(callback) : send(callback, attributes)
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::Graph.new)
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 == 0
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 == 0
106
+ if loc.zero?
103
107
  append_to(node, head)
104
108
  else
105
109
  append_to(node, ordered_reader.take(loc).last)
@@ -24,6 +24,10 @@ module ActiveFedora
24
24
  self
25
25
  end
26
26
 
27
+ def ids
28
+ association.reader.map(&:target_id)
29
+ end
30
+
27
31
  # Deletes the element at the specified index, returning that element, or nil if
28
32
  # the index is out of range.
29
33
  def delete_at(loc)
@@ -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, :find_with_conditions, :find_in_batches, :search_with_conditions, :search_in_batches, :search_by_id, :find_each, to: :all
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 "::ActionDispatch::Callbacks",
4
- "ActiveFedora::LdpCache"
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__)), "solr", "config")
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|
@@ -25,6 +25,7 @@ module ActiveFedora
25
25
 
26
26
  # Overrides ActiveTriples::Resource
27
27
  def persisted?
28
+ return true if frozen? && !datastream.new_record?
28
29
  @persisted ||= !datastream.new_record?
29
30
  end
30
31
  end
@@ -1,10 +1,8 @@
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
- autoload :Identifiable
8
6
  autoload :Persistence
9
7
  autoload :ProjectHydra
10
8
  autoload :FieldMap
@@ -29,5 +29,9 @@ module ActiveFedora
29
29
  super
30
30
  end
31
31
  end
32
+
33
+ def respond_to_missing?(method, *args)
34
+ array_delegable?(method) || super
35
+ end
32
36
  end
33
37
  end
@@ -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, "info:fedora/afmodel:ComplexCollection"], [:has_model, "info:fedora/afmodel:ActiveFedora_Base"]], 'OR'
19
- # # => _query_:"{!field f=has_model_ssim}info:fedora/afmodel:ComplexCollection" OR _query_:"{!field f=has_model_ssim}info:fedora/afmodel:ActiveFedora_Base"
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 = ' AND ')
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 = ' AND ')
35
- pairs_to_clauses(field_pairs).join(join_with)
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
- field_query(field, value)
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 field_query(key, value)
92
- "_query_:\"{!field f=#{key}}#{value.gsub('"', '\"')}\""
102
+ def query_clause(type, key, value)
103
+ "_query_:\"{!#{type} f=#{key}}#{value.gsub('"', '\"')}\""
93
104
  end
94
105
  end
95
106
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "10.0.0".freeze
2
+ VERSION = "11.0.0".freeze
3
3
  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
@@ -1,5 +1,5 @@
1
1
  #config/solr_wrapper_test.yml
2
- # version: 6.0.0
2
+ # version: 6.1.0
3
3
  port: 8985
4
4
  instance_dir: tmp/solr-test
5
5
  collection:
@@ -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 :contains, type: :string, default: nil, desc: "Name a file to attach"
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
- contains :descMetadata, class_name: "<%= options['datastream'] %>"
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['contains'] %>
23
- contains :<%= options['contains'] %>"
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
- # contains "attachment"
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
@@ -1,5 +1,5 @@
1
1
  def mock_yaml(hash, path)
2
- mock_file = double(path.split("/")[-1])
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
- let(:book) { Book.new(author: person) }
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 eq [@book, @book2]
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 eq [@book, @book2]
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 eq [@book, @book2]
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 eq [@book, @book2]
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 eq [@t1, @t2]
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 eq [@t3, @t4]
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
- subject { LibraryBook.create }
528
- before do
529
- @p1 = Page.create
530
- @p2 = Page.create
531
- subject.pages << @p1 << @p2
532
- subject.save!
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(subject).to receive(:before_count).with(1)
536
- expect(subject).to receive(:after_count).with(0)
537
- expect(subject).to receive(:say_hi).with(@p2).twice
538
- subject.pages.delete(@p2)
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
- subject { LibraryBook.new }
559
- before do
560
- @p1 = subject.pages.build
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(subject).to receive(:say_hi).with(@p2)
565
- subject.pages.delete(@p2)
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(subject).to be_a_kind_of(ActiveFedora::FilesHash)
71
- expect(subject).to be_empty
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
- subject.each_value do |ds|
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
- fds = ActiveFedora::File.new
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