active-fedora 9.9.0 → 9.10.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 (136) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +20 -6
  3. data/.travis.yml +2 -6
  4. data/History.txt +146 -0
  5. data/active-fedora.gemspec +11 -8
  6. data/lib/active_fedora/associations/association.rb +44 -14
  7. data/lib/active_fedora/associations/association_scope.rb +6 -2
  8. data/lib/active_fedora/associations/basic_contains_association.rb +2 -3
  9. data/lib/active_fedora/associations/belongs_to_association.rb +23 -14
  10. data/lib/active_fedora/associations/builder/association.rb +95 -41
  11. data/lib/active_fedora/associations/builder/belongs_to.rb +30 -2
  12. data/lib/active_fedora/associations/builder/collection_association.rb +36 -4
  13. data/lib/active_fedora/associations/builder/contains.rb +10 -5
  14. data/lib/active_fedora/associations/builder/directly_contains.rb +6 -8
  15. data/lib/active_fedora/associations/builder/directly_contains_one.rb +27 -20
  16. data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +7 -3
  17. data/lib/active_fedora/associations/builder/has_many.rb +8 -45
  18. data/lib/active_fedora/associations/builder/indirectly_contains.rb +6 -8
  19. data/lib/active_fedora/associations/builder/property.rb +6 -12
  20. data/lib/active_fedora/associations/builder/singular_association.rb +3 -5
  21. data/lib/active_fedora/associations/builder/singular_property.rb +5 -4
  22. data/lib/active_fedora/associations/collection_association.rb +22 -26
  23. data/lib/active_fedora/associations/collection_proxy.rb +1 -1
  24. data/lib/active_fedora/associations/contained_finder.rb +1 -2
  25. data/lib/active_fedora/associations/directly_contains_one_association.rb +2 -3
  26. data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +1 -1
  27. data/lib/active_fedora/associations/has_many_association.rb +24 -5
  28. data/lib/active_fedora/associations/rdf.rb +1 -20
  29. data/lib/active_fedora/associations.rb +1 -1
  30. data/lib/active_fedora/attached_files.rb +2 -2
  31. data/lib/active_fedora/attribute_assignment.rb +55 -0
  32. data/lib/active_fedora/attribute_methods/read.rb +29 -44
  33. data/lib/active_fedora/attribute_methods/write.rb +16 -19
  34. data/lib/active_fedora/attribute_methods.rb +149 -29
  35. data/lib/active_fedora/attributes.rb +6 -18
  36. data/lib/active_fedora/autosave_association.rb +8 -12
  37. data/lib/active_fedora/base.rb +2 -2
  38. data/lib/active_fedora/caching_connection.rb +1 -1
  39. data/lib/active_fedora/callbacks.rb +9 -9
  40. data/lib/active_fedora/common.rb +67 -0
  41. data/lib/active_fedora/core.rb +11 -23
  42. data/lib/active_fedora/default_model_mapper.rb +24 -0
  43. data/lib/active_fedora/errors.rb +42 -0
  44. data/lib/active_fedora/fedora.rb +1 -1
  45. data/lib/active_fedora/file/attributes.rb +9 -10
  46. data/lib/active_fedora/file.rb +19 -56
  47. data/lib/active_fedora/file_persistence.rb +27 -0
  48. data/lib/active_fedora/indexing.rb +15 -9
  49. data/lib/active_fedora/indexing_service.rb +4 -4
  50. data/lib/active_fedora/inheritance.rb +34 -0
  51. data/lib/active_fedora/ldp_resource.rb +1 -0
  52. data/lib/active_fedora/model.rb +18 -16
  53. data/lib/active_fedora/model_classifier.rb +77 -0
  54. data/lib/active_fedora/nested_attributes.rb +145 -18
  55. data/lib/active_fedora/persistence.rb +23 -5
  56. data/lib/active_fedora/predicates.rb +3 -0
  57. data/lib/active_fedora/qualified_dublin_core_datastream.rb +1 -1
  58. data/lib/active_fedora/query_result_builder.rb +12 -28
  59. data/lib/active_fedora/querying.rb +1 -1
  60. data/lib/active_fedora/rdf/datastream_indexing.rb +1 -1
  61. data/lib/active_fedora/reflection.rb +212 -80
  62. data/lib/active_fedora/relation/calculations.rb +1 -5
  63. data/lib/active_fedora/relation/finder_methods.rb +39 -26
  64. data/lib/active_fedora/relation.rb +17 -0
  65. data/lib/active_fedora/scoping/default.rb +117 -0
  66. data/lib/active_fedora/scoping/named.rb +152 -4
  67. data/lib/active_fedora/scoping.rb +85 -2
  68. data/lib/active_fedora/simple_datastream.rb +1 -1
  69. data/lib/active_fedora/solr_hit.rb +71 -0
  70. data/lib/active_fedora/solr_instance_loader.rb +12 -36
  71. data/lib/active_fedora/solr_query_builder.rb +20 -25
  72. data/lib/active_fedora/solr_service.rb +24 -13
  73. data/lib/active_fedora/type/boolean.rb +23 -0
  74. data/lib/active_fedora/type/value.rb +118 -0
  75. data/lib/active_fedora/type.rb +8 -0
  76. data/lib/active_fedora/validations.rb +14 -5
  77. data/lib/active_fedora/version.rb +1 -1
  78. data/lib/active_fedora/versionable.rb +8 -7
  79. data/lib/active_fedora/with_metadata/metadata_node.rb +2 -1
  80. data/lib/active_fedora.rb +35 -15
  81. data/lib/generators/active_fedora/config/fedora/fedora_generator.rb +4 -0
  82. data/lib/generators/active_fedora/config/fedora/templates/.fcrepo_wrapper +3 -0
  83. data/lib/generators/active_fedora/config/solr/solr_generator.rb +4 -0
  84. data/lib/generators/active_fedora/config/solr/templates/.solr_wrapper +5 -0
  85. data/lib/generators/active_fedora/config/solr/templates/solr/config/solrconfig.xml +15 -0
  86. data/solr/config/solrconfig.xml +15 -0
  87. data/spec/config_helper.rb +0 -5
  88. data/spec/integration/associations_spec.rb +5 -5
  89. data/spec/integration/attached_files_spec.rb +4 -4
  90. data/spec/integration/base_spec.rb +4 -4
  91. data/spec/integration/bug_spec.rb +0 -1
  92. data/spec/integration/collection_association_spec.rb +34 -3
  93. data/spec/integration/file_spec.rb +2 -2
  94. data/spec/integration/full_featured_model_spec.rb +4 -4
  95. data/spec/integration/has_and_belongs_to_many_associations_spec.rb +1 -1
  96. data/spec/integration/has_many_associations_spec.rb +30 -1
  97. data/spec/integration/indirect_container_spec.rb +1 -1
  98. data/spec/integration/nested_attribute_spec.rb +6 -0
  99. data/spec/integration/ntriples_datastream_spec.rb +4 -4
  100. data/spec/integration/om_datastream_spec.rb +7 -7
  101. data/spec/integration/persistence_spec.rb +1 -1
  102. data/spec/integration/relation_delegation_spec.rb +1 -1
  103. data/spec/integration/scoped_query_spec.rb +13 -13
  104. data/spec/integration/solr_hit_spec.rb +52 -0
  105. data/spec/samples/hydra-mods_article_datastream.rb +2 -2
  106. data/spec/spec_helper.rb +5 -9
  107. data/spec/unit/active_fedora_spec.rb +0 -26
  108. data/spec/unit/attributes_spec.rb +13 -7
  109. data/spec/unit/base_spec.rb +20 -0
  110. data/spec/unit/builder/has_and_belongs_to_many_spec.rb +2 -3
  111. data/spec/unit/callback_spec.rb +3 -8
  112. data/spec/unit/collection_proxy_spec.rb +1 -1
  113. data/spec/unit/default_model_mapper_spec.rb +39 -0
  114. data/spec/unit/file_spec.rb +21 -2
  115. data/spec/unit/finder_methods_spec.rb +30 -6
  116. data/spec/unit/has_and_belongs_to_many_association_spec.rb +4 -4
  117. data/spec/unit/has_many_association_spec.rb +25 -3
  118. data/spec/unit/indexing_spec.rb +17 -3
  119. data/spec/unit/model_classifier_spec.rb +49 -0
  120. data/spec/unit/model_spec.rb +0 -9
  121. data/spec/unit/ntriples_datastream_spec.rb +16 -16
  122. data/spec/unit/om_datastream_spec.rb +7 -7
  123. data/spec/unit/qualified_dublin_core_datastream_spec.rb +1 -1
  124. data/spec/unit/query_result_builder_spec.rb +4 -10
  125. data/spec/unit/query_spec.rb +28 -28
  126. data/spec/unit/rdf/indexing_service_spec.rb +16 -16
  127. data/spec/unit/reflection_spec.rb +2 -2
  128. data/spec/unit/scoping_spec.rb +67 -0
  129. data/spec/unit/simple_datastream_spec.rb +2 -2
  130. data/spec/unit/solr_config_options_spec.rb +29 -32
  131. data/spec/unit/solr_hit_spec.rb +58 -0
  132. data/spec/unit/solr_query_builder_spec.rb +9 -1
  133. data/spec/unit/solr_service_spec.rb +19 -3
  134. data/spec/unit/validations_spec.rb +1 -1
  135. metadata +82 -20
  136. data/spec/support/freeze_mocks.rb +0 -12
@@ -49,19 +49,19 @@ module ActiveFedora
49
49
  end
50
50
 
51
51
  def reify_solr_result(hit, opts = {})
52
- Deprecation.warn SolrService, "SolrService.reify_solr_result is deprecated. Use QueryResultBuilder.reify_solr_result instead. This will be removed in active-fedora 10.0"
52
+ Deprecation.warn SolrService, "SolrService.reify_solr_result is deprecated. Use SolrHit#reify instead. This will be removed in active-fedora 10.0"
53
53
  QueryResultBuilder.reify_solr_result(hit, opts)
54
54
  end
55
55
 
56
56
  # Returns all possible classes for the solr object
57
57
  def classes_from_solr_document(hit, opts = {})
58
- Deprecation.warn SolrService, "SolrService.classes_from_solr_document is deprecated. Use QueryResultBuilder.classes_from_solr_document instead. This will be removed in active-fedora 10.0"
58
+ Deprecation.warn SolrService, "SolrService.classes_from_solr_document is deprecated. Use SolrHit#models instead. This will be removed in active-fedora 10.0"
59
59
  QueryResultBuilder.classes_from_solr_document(hit, opts)
60
60
  end
61
61
 
62
62
  # Returns the best singular class for the solr object
63
63
  def class_from_solr_document(hit, opts = {})
64
- Deprecation.warn SolrService, "SolrService.class_from_solr_document is deprecated. Use QueryResultBuilder.class_from_solr_document instead. This will be removed in active-fedora 10.0"
64
+ Deprecation.warn SolrService, "SolrService.class_from_solr_document is deprecated. Use SolrHit#model instead. This will be removed in active-fedora 10.0"
65
65
  QueryResultBuilder.class_from_solr_document(hit, opts)
66
66
  end
67
67
 
@@ -83,8 +83,8 @@ module ActiveFedora
83
83
  # @param [String] key
84
84
  # @param [String] value
85
85
  def raw_query(key, value)
86
- Deprecation.warn SolrService, "SolrService.raw_query is deprecated. Use SolrQueryBuilder.raw_query instead. This will be removed in active-fedora 10.0"
87
- SolrQueryBuilder.raw_query(key, value)
86
+ Deprecation.warn SolrService, "SolrService.raw_query is deprecated. Use SolrQueryBuilder.construct_query instead. This will be removed in active-fedora 10.0"
87
+ SolrQueryBuilder.construct_query(key, value)
88
88
  end
89
89
 
90
90
  def solr_name(*args)
@@ -97,20 +97,31 @@ module ActiveFedora
97
97
  # @param [String] join_with ('AND') the value we're joining the clauses with
98
98
  # @example
99
99
  # construct_query_for_rel [[:has_model, "info:fedora/afmodel:ComplexCollection"], [:has_model, "info:fedora/afmodel:ActiveFedora_Base"]], 'OR'
100
- # # => _query_:"{!raw f=has_model_ssim}info:fedora/afmodel:ComplexCollection" OR _query_:"{!raw f=has_model_ssim}info:fedora/afmodel:ActiveFedora_Base"
100
+ # # => _query_:"{!field f=has_model_ssim}info:fedora/afmodel:ComplexCollection" OR _query_:"{!field f=has_model_ssim}info:fedora/afmodel:ActiveFedora_Base"
101
101
  #
102
- # construct_query_for_rel [[Book.reflect_on_association(:library), "foo/bar/baz"]]
102
+ # construct_query_for_rel [[Book._reflect_on_association(:library), "foo/bar/baz"]]
103
103
  def construct_query_for_rel(field_pairs, join_with = 'AND')
104
104
  Deprecation.warn SolrService, "SolrService.construct_query_for_rel is deprecated. Use SolrQueryBuilder.construct_query_for_rel instead. This will be removed in active-fedora 10.0"
105
105
  SolrQueryBuilder.construct_query_for_rel(field_pairs, join_with)
106
106
  end
107
107
 
108
+ def get(query, args = {})
109
+ args = args.merge(q: query, qt: 'standard')
110
+ SolrService.instance.conn.get(select_path, params: args)
111
+ end
112
+
108
113
  def query(query, args = {})
109
114
  raw = args.delete(:raw)
110
- args = args.merge(q: query, qt: 'standard')
111
- result = SolrService.instance.conn.get(select_path, params: args)
112
- return result if raw
113
- result['response']['docs']
115
+ result = get(query, args)
116
+
117
+ if raw
118
+ Deprecation.warn SolrService, "SolrService.query with raw: true is deprecated. Use SolrService.get instead. This will be removed in active-fedora 10.0"
119
+ return result
120
+ end
121
+
122
+ result['response']['docs'].map do |doc|
123
+ ActiveFedora::SolrHit.new(doc)
124
+ end
114
125
  end
115
126
 
116
127
  def delete(id)
@@ -122,8 +133,8 @@ module ActiveFedora
122
133
  # @param [Hash] args arguments to pass through to `args' param of SolrService.query (note that :rows will be overwritten to 0)
123
134
  # @return [Integer] number of records matching
124
135
  def count(query, args = {})
125
- args = args.merge(raw: true, rows: 0)
126
- SolrService.query(query, args)['response']['numFound'].to_i
136
+ args = args.merge(rows: 0)
137
+ SolrService.get(query, args)['response']['numFound'].to_i
127
138
  end
128
139
 
129
140
  # @param [Hash] doc the document to index
@@ -0,0 +1,23 @@
1
+ # DO NOT EDIT THIS FILE
2
+ # Plucked from ActiveModel::Type::Boolean in Rails 5
3
+ module ActiveFedora
4
+ module Type
5
+ class Boolean < Value # :nodoc:
6
+ FALSE_VALUES = [false, 0, '0', 'f', 'F', 'false', 'FALSE', 'off', 'OFF'].to_set
7
+
8
+ def type
9
+ :boolean
10
+ end
11
+
12
+ private
13
+
14
+ def cast_value(value)
15
+ if value == ''
16
+ nil
17
+ else
18
+ !FALSE_VALUES.include?(value)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,118 @@
1
+ # DO NOT EDIT THIS FILE
2
+ # Plucked from ActiveModel::Type::Boolean in Rails 5
3
+ module ActiveFedora
4
+ module Type
5
+ class Value
6
+ attr_reader :precision, :scale, :limit
7
+
8
+ def initialize(precision: nil, limit: nil, scale: nil)
9
+ @precision = precision
10
+ @scale = scale
11
+ @limit = limit
12
+ end
13
+
14
+ def type # :nodoc:
15
+ end
16
+
17
+ # Converts a value from database input to the appropriate ruby type. The
18
+ # return value of this method will be returned from
19
+ # ActiveRecord::AttributeMethods::Read#read_attribute. The default
20
+ # implementation just calls Value#cast.
21
+ #
22
+ # +value+ The raw input, as provided from the database.
23
+ def deserialize(value)
24
+ cast(value)
25
+ end
26
+
27
+ # Type casts a value from user input (e.g. from a setter). This value may
28
+ # be a string from the form builder, or a ruby object passed to a setter.
29
+ # There is currently no way to differentiate between which source it came
30
+ # from.
31
+ #
32
+ # The return value of this method will be returned from
33
+ # ActiveRecord::AttributeMethods::Read#read_attribute. See also:
34
+ # Value#cast_value.
35
+ #
36
+ # +value+ The raw input, as provided to the attribute setter.
37
+ def cast(value)
38
+ cast_value(value) unless value.nil?
39
+ end
40
+
41
+ # Casts a value from the ruby type to a type that the database knows how
42
+ # to understand. The returned value from this method should be a
43
+ # +String+, +Numeric+, +Date+, +Time+, +Symbol+, +true+, +false+, or
44
+ # +nil+.
45
+ def serialize(value)
46
+ value
47
+ end
48
+
49
+ # Type casts a value for schema dumping. This method is private, as we are
50
+ # hoping to remove it entirely.
51
+ def type_cast_for_schema(value) # :nodoc:
52
+ value.inspect
53
+ end
54
+
55
+ # These predicates are not documented, as I need to look further into
56
+ # their use, and see if they can be removed entirely.
57
+ def binary? # :nodoc:
58
+ false
59
+ end
60
+
61
+ # Determines whether a value has changed for dirty checking. +old_value+
62
+ # and +new_value+ will always be type-cast. Types should not need to
63
+ # override this method.
64
+ def changed?(old_value, new_value, _new_value_before_type_cast)
65
+ old_value != new_value
66
+ end
67
+
68
+ # Determines whether the mutable value has been modified since it was
69
+ # read. Returns +false+ by default. If your type returns an object
70
+ # which could be mutated, you should override this method. You will need
71
+ # to either:
72
+ #
73
+ # - pass +new_value+ to Value#serialize and compare it to
74
+ # +raw_old_value+
75
+ #
76
+ # or
77
+ #
78
+ # - pass +raw_old_value+ to Value#deserialize and compare it to
79
+ # +new_value+
80
+ #
81
+ # +raw_old_value+ The original value, before being passed to
82
+ # +deserialize+.
83
+ #
84
+ # +new_value+ The current value, after type casting.
85
+ def changed_in_place?(_raw_old_value, _new_value)
86
+ false
87
+ end
88
+
89
+ def map(value) # :nodoc:
90
+ yield value
91
+ end
92
+
93
+ def ==(other)
94
+ self.class == other.class &&
95
+ precision == other.precision &&
96
+ scale == other.scale &&
97
+ limit == other.limit
98
+ end
99
+ alias eql? ==
100
+
101
+ def hash
102
+ [self.class, precision, scale, limit].hash
103
+ end
104
+
105
+ def assert_valid_value(*)
106
+ end
107
+
108
+ private
109
+
110
+ # Convenience method for types which do not need separate type casting
111
+ # behavior for user and database inputs. Called by Value#cast for
112
+ # values except +nil+.
113
+ def cast_value(value) # :doc:
114
+ value
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,8 @@
1
+
2
+ require 'active_fedora/type/value'
3
+ require 'active_fedora/type/boolean'
4
+
5
+ module ActiveFedora
6
+ module Type
7
+ end
8
+ end
@@ -53,7 +53,7 @@ module ActiveFedora
53
53
  # Attempts to save the record just like Base#save but will raise a +RecordInvalid+ exception instead of returning false
54
54
  # if the record is not valid.
55
55
  def save!(options = {})
56
- perform_validations(options) ? super : raise(RecordInvalid, self)
56
+ perform_validations(options) ? super : raise_validation_error
57
57
  end
58
58
 
59
59
  # Runs all the validations within the specified context. Returns true if no errors are found,
@@ -65,11 +65,13 @@ module ActiveFedora
65
65
  # Validations with no <tt>:on</tt> option will run no matter the context. Validations with
66
66
  # some <tt>:on</tt> option will only run in the specified context.
67
67
  def valid?(context = nil)
68
- context ||= (new_record? ? :create : :update)
68
+ context ||= default_validation_context
69
69
  output = super(context)
70
70
  errors.empty? && output
71
71
  end
72
72
 
73
+ alias validate valid?
74
+
73
75
  # Test to see if the given field is required
74
76
  # @param [Symbol] key a field
75
77
  # @return [Boolean] is it required or not
@@ -79,9 +81,16 @@ module ActiveFedora
79
81
 
80
82
  protected
81
83
 
82
- def perform_validations(options = {})
83
- perform_validation = options[:validate] != false
84
- perform_validation ? valid?(options[:context]) : true
84
+ def default_validation_context
85
+ new_record? ? :create : :update
86
+ end
87
+
88
+ def raise_validation_error
89
+ raise RecordInvalid, self
90
+ end
91
+
92
+ def perform_validations(options = {}) # :nodoc:
93
+ options[:validate] == false || valid?(options[:context])
85
94
  end
86
95
  end
87
96
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "9.9.0".freeze
2
+ VERSION = "9.10.0".freeze
3
3
  end
@@ -25,10 +25,14 @@ module ActiveFedora
25
25
  # Returns an array of ActiveFedora::VersionsGraph::ResourceVersion objects.
26
26
  # Excludes auto-snapshot versions from Fedora.
27
27
  def versions(reload = false)
28
+ response = versions_request
29
+
30
+ return ActiveFedora::VersionsGraph.new unless response
31
+
28
32
  if reload
29
- @versions = ActiveFedora::VersionsGraph.new << ::RDF::Reader.for(:ttl).new(versions_request)
33
+ @versions = ActiveFedora::VersionsGraph.new << versions_request.reader
30
34
  else
31
- @versions ||= ActiveFedora::VersionsGraph.new << ::RDF::Reader.for(:ttl).new(versions_request)
35
+ @versions ||= ActiveFedora::VersionsGraph.new << versions_request.reader
32
36
  end
33
37
  end
34
38
 
@@ -57,11 +61,8 @@ module ActiveFedora
57
61
  private
58
62
 
59
63
  def versions_request
60
- return '' unless has_versions?
61
- resp = ActiveFedora.fedora.connection.get(versions_uri)
62
- raise ActiveFedoraError, status_message(resp) unless resp.success?
63
- raise ActiveFedoraError, bad_headers(resp) unless resp.headers['content-type'] == 'text/turtle'
64
- resp.body
64
+ return false unless has_versions?
65
+ ActiveFedora.fedora.connection.get(versions_uri)
65
66
  end
66
67
 
67
68
  def versions_uri
@@ -2,6 +2,7 @@ module ActiveFedora
2
2
  module WithMetadata
3
3
  class MetadataNode < ActiveTriples::Resource
4
4
  include ActiveModel::Dirty
5
+ property :mime_type, predicate: ::RDF::URI("http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#hasMimeType")
5
6
  attr_reader :file
6
7
 
7
8
  def initialize(file)
@@ -45,7 +46,7 @@ module ActiveFedora
45
46
 
46
47
  def changed_attributes
47
48
  super.tap do |changed|
48
- changed['type'] = true if type.present?
49
+ changed['type'] = true if type.present? && new_record?
49
50
  end
50
51
  end
51
52
 
data/lib/active_fedora.rb CHANGED
@@ -9,9 +9,6 @@ require 'active_support/core_ext/hash/indifferent_access'
9
9
  require 'active_support/core_ext/hash/except'
10
10
  require 'active_triples'
11
11
 
12
- SOLR_DOCUMENT_ID = Solrizer.default_field_mapper.id_field unless defined?(SOLR_DOCUMENT_ID)
13
- ENABLE_SOLR_UPDATES = true unless defined?(ENABLE_SOLR_UPDATES)
14
-
15
12
  # Monkey patching RDF::Literal::DateTime to support fractional seconds.
16
13
  # See https://github.com/projecthydra/active_fedora/issues/497
17
14
  # Also monkey patches in a fix for timezones to be stored properly.
@@ -43,6 +40,7 @@ module ActiveFedora #:nodoc:
43
40
  autoload :AssociationRelation
44
41
  autoload :Associations
45
42
  autoload :AttachedFiles
43
+ autoload :AttributeAssignment
46
44
  autoload :AttributeMethods
47
45
  autoload :Attributes
48
46
  autoload :AutosaveAssociation
@@ -53,6 +51,7 @@ module ActiveFedora #:nodoc:
53
51
  autoload :Checksum
54
52
  autoload :CleanConnection
55
53
  autoload :Config
54
+ autoload :Common
56
55
  autoload :Core
57
56
  autoload_under 'containers' do
58
57
  autoload :Container
@@ -68,11 +67,13 @@ module ActiveFedora #:nodoc:
68
67
  autoload :OmAttribute
69
68
  autoload :RdfDatastreamAttribute
70
69
  end
70
+ autoload :DefaultModelMapper
71
71
  autoload :Fedora
72
72
  autoload :FedoraAttributes
73
73
  autoload :File
74
74
  autoload :FileConfigurator
75
75
  autoload :FilePathBuilder
76
+ autoload :FilePersistence
76
77
  autoload :FileRelation
77
78
  autoload :FilesHash
78
79
  autoload :FixityService
@@ -81,12 +82,14 @@ module ActiveFedora #:nodoc:
81
82
  autoload :Indexing
82
83
  autoload :IndexingService
83
84
  autoload :InheritableAccessors
85
+ autoload :Inheritance
84
86
  autoload :InboundRelationConnection
85
87
  autoload :LdpCache
86
88
  autoload :LdpResource
87
89
  autoload :LdpResourceService
88
90
  autoload :LoadableFromJson
89
91
  autoload :Model
92
+ autoload :ModelClassifier
90
93
  autoload :NestedAttributes
91
94
  autoload :NomDatastream
92
95
  autoload :NullRelation
@@ -121,11 +124,13 @@ module ActiveFedora #:nodoc:
121
124
  autoload :Serialization
122
125
  autoload :SimpleDatastream
123
126
  autoload :SchemaIndexingStrategy
127
+ autoload :SolrHit
124
128
  autoload :SolrInstanceLoader
125
129
  autoload :SolrQueryBuilder
126
130
  autoload :SolrService
127
131
  autoload :SparqlInsert
128
132
  autoload :Predicates
133
+ autoload :Type
129
134
  autoload :Validations
130
135
  autoload :Versionable
131
136
  autoload :VersionsGraph
@@ -245,18 +250,33 @@ module ActiveFedora #:nodoc:
245
250
  # @example Search within ActiveFedora::RdfNode for a class called "TermProxy"
246
251
  # ActiveFedora.class_from_string("TermProxy", ActiveFedora::RdfNode)
247
252
  # => ActiveFedora::RdfNode::TermProxy
248
- def class_from_string(full_class_name, container_class = Kernel)
249
- container_class = container_class.name if container_class.is_a? Module
250
- container_parts = container_class.split('::')
251
- (container_parts + full_class_name.split('::')).flatten.inject(Kernel) do |mod, class_name|
252
- if mod == Kernel
253
- Object.const_get(class_name)
254
- elsif mod.const_defined? class_name.to_sym
255
- mod.const_get(class_name)
256
- else
257
- container_parts.pop
258
- class_from_string(class_name, container_parts.join('::'))
259
- end
253
+ def class_from_string(*args)
254
+ ActiveFedora::ModelClassifier.class_from_string(*args)
255
+ end
256
+
257
+ def model_mapper
258
+ ActiveFedora::DefaultModelMapper.new
259
+ end
260
+
261
+ def index_field_mapper
262
+ Solrizer.default_field_mapper
263
+ end
264
+
265
+ def id_field
266
+ if defined?(SOLR_DOCUMENT_ID) && !SOLR_DOCUMENT_ID.nil?
267
+ SOLR_DOCUMENT_ID
268
+ elsif defined?(Solrizer)
269
+ Solrizer.default_field_mapper.id_field
270
+ else
271
+ 'id'.freeze
272
+ end
273
+ end
274
+
275
+ def enable_solr_updates?
276
+ if defined?(ENABLE_SOLR_UPDATES)
277
+ ENABLE_SOLR_UPDATES
278
+ else
279
+ true
260
280
  end
261
281
  end
262
282
  end
@@ -7,5 +7,9 @@ module ActiveFedora
7
7
  def generate
8
8
  copy_file('fedora.yml', 'config/fedora.yml')
9
9
  end
10
+
11
+ def fcrepo_wrapper_config
12
+ copy_file '.fcrepo_wrapper', '.fcrepo_wrapper'
13
+ end
10
14
  end
11
15
  end
@@ -0,0 +1,3 @@
1
+ # Place any default configuration for solr_wrapper here
2
+ port: 8984
3
+ enable_jms: false
@@ -9,5 +9,9 @@ module ActiveFedora
9
9
  copy_file 'solr.yml', 'config/solr.yml', force: true
10
10
  directory 'solr', 'solr'
11
11
  end
12
+
13
+ def solr_wrapper_config
14
+ copy_file '.solr_wrapper', '.solr_wrapper'
15
+ end
12
16
  end
13
17
  end
@@ -0,0 +1,5 @@
1
+ # Place any default configuration for solr_wrapper here
2
+ # port: 8983
3
+ collection:
4
+ dir: solr/config/
5
+ name: hydra-development
@@ -57,6 +57,21 @@
57
57
  <defaultQuery>*:*</defaultQuery>
58
58
  </admin>
59
59
 
60
+ <updateHandler class="solr.DirectUpdateHandler2">
61
+ <updateLog>
62
+ <str name="dir">${solr.ulog.dir:}</str>
63
+ </updateLog>
64
+
65
+ <autoCommit>
66
+ <maxTime>${solr.autoCommit.maxTime:15000}</maxTime>
67
+ <openSearcher>false</openSearcher>
68
+ </autoCommit>
69
+
70
+ <autoSoftCommit>
71
+ <maxTime>${solr.autoSoftCommit.maxTime:-1}</maxTime>
72
+ </autoSoftCommit>
73
+ </updateHandler>
74
+
60
75
  <!-- SearchHandler
61
76
 
62
77
  http://wiki.apache.org/solr/SearchHandler
@@ -57,6 +57,21 @@
57
57
  <defaultQuery>*:*</defaultQuery>
58
58
  </admin>
59
59
 
60
+ <updateHandler class="solr.DirectUpdateHandler2">
61
+ <updateLog>
62
+ <str name="dir">${solr.ulog.dir:}</str>
63
+ </updateLog>
64
+
65
+ <autoCommit>
66
+ <maxTime>${solr.autoCommit.maxTime:15000}</maxTime>
67
+ <openSearcher>false</openSearcher>
68
+ </autoCommit>
69
+
70
+ <autoSoftCommit>
71
+ <maxTime>${solr.autoSoftCommit.maxTime:-1}</maxTime>
72
+ </autoSoftCommit>
73
+ </updateHandler>
74
+
60
75
  <!-- SearchHandler
61
76
 
62
77
  http://wiki.apache.org/solr/SearchHandler
@@ -19,8 +19,3 @@ end
19
19
  def unstub_rails
20
20
  Object.send(:remove_const, :Rails) if defined?(Rails)
21
21
  end
22
-
23
- def setup_pretest_env
24
- ENV['RAILS_ENV'] = 'test'
25
- ENV['environment'] = 'test'
26
- end
@@ -234,8 +234,8 @@ describe ActiveFedora::Base do
234
234
 
235
235
  solr_resp = @library.books(response_format: :solr)
236
236
  expect(solr_resp.size).to eq 2
237
- expect(solr_resp[0]['id']).to eq @book.id
238
- expect(solr_resp[1]['id']).to eq @book2.id
237
+ expect(solr_resp[0].id).to eq @book.id
238
+ expect(solr_resp[1].id).to eq @book2.id
239
239
  end
240
240
  end
241
241
 
@@ -584,7 +584,7 @@ describe ActiveFedora::Base do
584
584
  end
585
585
 
586
586
  it "it should find the reflection that bears the predicate" do
587
- expect(MediaObject.new.association(:baubles).send(:find_reflection)).to eq Bauble.reflect_on_association(:media_object)
587
+ expect(MediaObject.new.association(:baubles).send(:find_reflection)).to eq Bauble._reflect_on_association(:media_object)
588
588
  end
589
589
  end
590
590
 
@@ -604,7 +604,7 @@ describe ActiveFedora::Base do
604
604
  end
605
605
 
606
606
  it "it should find the reflection that bears the predicate" do
607
- expect(MediaObject.new.association(:parts).send(:find_reflection)).to eq MasterFile.reflect_on_association(:media_object)
607
+ expect(MediaObject.new.association(:parts).send(:find_reflection)).to eq MasterFile._reflect_on_association(:media_object)
608
608
  end
609
609
  end
610
610
 
@@ -624,7 +624,7 @@ describe ActiveFedora::Base do
624
624
  end
625
625
 
626
626
  it "it should find the reflection that bears the predicate" do
627
- expect(MediaObject.new.association(:baubles).send(:find_reflection)).to eq MediaObject.reflect_on_association(:baubles)
627
+ expect(MediaObject.new.association(:baubles).send(:find_reflection)).to eq MediaObject._reflect_on_association(:baubles)
628
628
  end
629
629
  end
630
630
  end
@@ -63,13 +63,13 @@ describe ActiveFedora::AttachedFiles do
63
63
 
64
64
  it "creates datastreams from the spec on new objects" do
65
65
  has_file.file_ds.content = "blah blah blah"
66
- expect(has_file.file_ds).to be_changed
67
- expect(has_file.file_ds2).to_not be_changed # no autocreate
66
+ expect(has_file.file_ds).to be_content_changed
67
+ expect(has_file.file_ds2).to_not be_content_changed # no autocreate
68
68
  expect(has_file.file_ds2).to be_new_record
69
69
  has_file.save
70
70
  has_file.reload
71
- expect(has_file.file_ds).to_not be_changed
72
- expect(has_file.file_ds2).to_not be_changed # no autocreate
71
+ expect(has_file.file_ds).to_not be_content_changed
72
+ expect(has_file.file_ds2).to_not be_content_changed # no autocreate
73
73
  expect(has_file.file_ds2).to be_new_record
74
74
  end
75
75
  end
@@ -22,8 +22,8 @@ describe ActiveFedora::Base do
22
22
  obj = described_class.find(@obj.id)
23
23
  expect(obj.foo).to_not be_new_record
24
24
  expect(obj.foo.person).to eq ['bob']
25
- person_field = ActiveFedora::SolrQueryBuilder.solr_name('foo__person', type: :string)
26
- solr_result = ActiveFedora::SolrService.query("{!raw f=id}#{@obj.id}", fl: "id #{person_field}").first
25
+ person_field = ActiveFedora.index_field_mapper.solr_name('foo__person', type: :string)
26
+ solr_result = ActiveFedora::SolrService.query("{!field f=id}#{@obj.id}", fl: "id #{person_field}").first
27
27
  expect(solr_result).to eq("id" => @obj.id, person_field => ['bob'])
28
28
  end
29
29
  end
@@ -41,7 +41,7 @@ describe ActiveFedora::Base do
41
41
  end
42
42
  it "saves the datastream." do
43
43
  expect(MockAFBaseRelationship.find(@release.id).foo.person).to eq ['frank']
44
- person_field = ActiveFedora::SolrQueryBuilder.solr_name('foo__person', type: :string)
44
+ person_field = ActiveFedora.index_field_mapper.solr_name('foo__person', type: :string)
45
45
  expect(ActiveFedora::SolrService.query("id:\"#{@release.id}\"", fl: "id #{person_field}").first).to eq("id" => @release.id, person_field => ['frank'])
46
46
  end
47
47
  end
@@ -164,7 +164,7 @@ describe ActiveFedora::Base do
164
164
  let(:obj) { ExampleBase.new }
165
165
  it "configures properties and solrize them" do
166
166
  obj.title = ["Test"]
167
- expect(obj.to_solr[ActiveFedora::SolrQueryBuilder.solr_name("title", :symbol)]).to eq ["Test"]
167
+ expect(obj.to_solr[ActiveFedora.index_field_mapper.solr_name("title", :symbol)]).to eq ["Test"]
168
168
  end
169
169
  end
170
170
 
@@ -3,7 +3,6 @@ require 'spec_helper'
3
3
  require 'active_fedora'
4
4
  require 'active_fedora/model'
5
5
  require "rexml/document"
6
- include ActiveFedora::Model
7
6
 
8
7
  describe 'bugs' do
9
8
  before do