active-fedora 9.0.0 → 9.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/History.txt +97 -0
  3. data/README.md +40 -28
  4. data/active-fedora.gemspec +2 -1
  5. data/lib/active_fedora/associations/builder/contains.rb +5 -1
  6. data/lib/active_fedora/associations/builder/has_many.rb +1 -1
  7. data/lib/active_fedora/associations/collection_association.rb +1 -18
  8. data/lib/active_fedora/associations/contains_association.rb +3 -1
  9. data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +12 -10
  10. data/lib/active_fedora/associations.rb +1 -1
  11. data/lib/active_fedora/attached_files.rb +7 -4
  12. data/lib/active_fedora/attributes/property_builder.rb +1 -0
  13. data/lib/active_fedora/attributes.rb +36 -9
  14. data/lib/active_fedora/change_set.rb +2 -2
  15. data/lib/active_fedora/clean_connection.rb +40 -0
  16. data/lib/active_fedora/core/fedora_id_translator.rb +12 -0
  17. data/lib/active_fedora/core/fedora_uri_translator.rb +9 -0
  18. data/lib/active_fedora/core.rb +26 -38
  19. data/lib/active_fedora/errors.rb +4 -0
  20. data/lib/active_fedora/fedora.rb +22 -4
  21. data/lib/active_fedora/fedora_attributes.rb +25 -1
  22. data/lib/active_fedora/file.rb +30 -24
  23. data/lib/active_fedora/indexing/map.rb +46 -0
  24. data/lib/active_fedora/indexing.rb +14 -0
  25. data/lib/active_fedora/inheritable_accessors.rb +26 -0
  26. data/lib/active_fedora/loadable_from_json.rb +5 -1
  27. data/lib/active_fedora/nom_datastream.rb +6 -4
  28. data/lib/active_fedora/persistence.rb +11 -7
  29. data/lib/active_fedora/rdf/datastream_indexing.rb +4 -0
  30. data/lib/active_fedora/rdf/fcrepo4.rb +1 -0
  31. data/lib/active_fedora/rdf/indexing_service.rb +18 -11
  32. data/lib/active_fedora/rdf/ldp.rb +3 -0
  33. data/lib/active_fedora/rdf/ntriples_rdf_datastream.rb +0 -4
  34. data/lib/active_fedora/rdf/rdf_datastream.rb +12 -1
  35. data/lib/active_fedora/reflection.rb +3 -1
  36. data/lib/active_fedora/relation/finder_methods.rb +36 -5
  37. data/lib/active_fedora/solr_query_builder.rb +1 -1
  38. data/lib/active_fedora/solr_service.rb +1 -1
  39. data/lib/active_fedora/version.rb +1 -1
  40. data/lib/active_fedora/versions_graph.rb +7 -8
  41. data/lib/active_fedora.rb +6 -0
  42. data/spec/integration/associations_spec.rb +64 -21
  43. data/spec/integration/attached_files_spec.rb +24 -0
  44. data/spec/integration/attributes_spec.rb +49 -3
  45. data/spec/integration/belongs_to_association_spec.rb +118 -47
  46. data/spec/integration/clean_connection_spec.rb +21 -0
  47. data/spec/integration/collection_association_spec.rb +46 -0
  48. data/spec/integration/field_to_solr_name_spec.rb +11 -7
  49. data/spec/integration/has_and_belongs_to_many_associations_spec.rb +180 -137
  50. data/spec/integration/has_many_associations_spec.rb +6 -2
  51. data/spec/integration/json_serialization_spec.rb +11 -5
  52. data/spec/integration/nested_attribute_spec.rb +3 -1
  53. data/spec/integration/ntriples_datastream_spec.rb +23 -17
  54. data/spec/integration/persistence_spec.rb +3 -1
  55. data/spec/integration/query_result_builder_spec.rb +2 -2
  56. data/spec/integration/relation_delegation_spec.rb +3 -1
  57. data/spec/integration/scoped_query_spec.rb +3 -1
  58. data/spec/integration/solr_instance_loader_spec.rb +4 -2
  59. data/spec/integration/versionable_spec.rb +38 -1
  60. data/spec/samples/samples.rb +0 -1
  61. data/spec/spec_helper.rb +1 -0
  62. data/spec/unit/active_fedora_spec.rb +4 -2
  63. data/spec/unit/attributes_spec.rb +52 -12
  64. data/spec/unit/base_active_model_spec.rb +5 -3
  65. data/spec/unit/base_spec.rb +102 -2
  66. data/spec/unit/callback_spec.rb +4 -2
  67. data/spec/unit/change_set_spec.rb +4 -2
  68. data/spec/unit/core/fedora_id_translator_spec.rb +20 -0
  69. data/spec/unit/core/fedora_uri_translator_spec.rb +19 -0
  70. data/spec/unit/core_spec.rb +54 -2
  71. data/spec/unit/has_many_association_spec.rb +27 -2
  72. data/spec/unit/ntriples_datastream_spec.rb +24 -20
  73. data/spec/unit/qualified_dublin_core_datastream_spec.rb +0 -6
  74. data/spec/unit/query_result_builder_spec.rb +1 -1
  75. data/spec/unit/rdf/indexing_service_spec.rb +19 -17
  76. data/spec/unit/rdf_resource_datastream_spec.rb +14 -10
  77. data/spec/unit/reflection_spec.rb +44 -0
  78. data/spec/unit/simple_datastream_spec.rb +34 -0
  79. data/spec/unit/solr_query_builder_spec.rb +1 -1
  80. data/spec/unit/validations_spec.rb +4 -2
  81. metadata +28 -13
  82. data/spec/samples/marpa-dc_datastream.rb +0 -102
  83. data/spec/samples/models/audio_record.rb +0 -29
  84. data/spec/samples/models/image.rb +0 -5
  85. data/spec/samples/models/oral_history.rb +0 -36
  86. data/spec/samples/models/seminar.rb +0 -29
  87. data/spec/samples/models/seminar_audio_file.rb +0 -32
  88. data/spec/samples/oral_history_sample_model.rb +0 -30
  89. data/spec/samples/special_thing.rb +0 -44
@@ -14,14 +14,25 @@ module ActiveFedora
14
14
  # :singleton-method
15
15
  #
16
16
  # Accepts a proc that takes an id and transforms it to a URI
17
- mattr_accessor :translate_id_to_uri, instance_writer: false
17
+ mattr_reader :translate_id_to_uri do
18
+ FedoraIdTranslator
19
+ end
20
+
21
+ def self.translate_id_to_uri=(translator)
22
+ @@translate_id_to_uri = translator || FedoraIdTranslator
23
+ end
18
24
 
19
25
  ##
20
26
  # :singleton-method
21
27
  #
22
28
  # Accepts a proc that takes a uri and transforms it to an id
23
- mattr_accessor :translate_uri_to_id, instance_writer: false
29
+ mattr_reader :translate_uri_to_id do
30
+ FedoraUriTranslator
31
+ end
24
32
 
33
+ def self.translate_uri_to_id=(translator)
34
+ @@translate_uri_to_id = translator || FedoraUriTranslator
35
+ end
25
36
  end
26
37
 
27
38
  def ldp_source
@@ -33,13 +44,14 @@ module ActiveFedora
33
44
  # Also, if +attrs+ does not contain +:id+ but does contain +:namespace+ it will pass the
34
45
  # +:namespace+ value to Fedora::Repository.nextid to generate the next id available within
35
46
  # the given namespace.
36
- def initialize(attributes_or_resource_or_url = nil, &block)
47
+ def initialize(attributes_or_id = nil, &block)
37
48
  init_internals
38
- attributes = initialize_resource_and_attributes(attributes_or_resource_or_url)
49
+ attributes = initialize_attributes(attributes_or_id)
50
+ @ldp_source = build_ldp_resource(attributes.delete(:id))
39
51
  raise IllegalOperation, "Attempting to recreate existing ldp_source: `#{ldp_source.subject}'" unless ldp_source.new?
40
52
  assert_content_model
41
53
  load_attached_files
42
- self.attributes = attributes if attributes
54
+ self.attributes = attributes
43
55
 
44
56
  yield self if block_given?
45
57
  run_callbacks :initialize
@@ -133,27 +145,14 @@ module ActiveFedora
133
145
  # Transforms an id into a uri
134
146
  # if translate_id_to_uri is set it uses that proc, otherwise just the default
135
147
  def id_to_uri(id)
136
- if translate_id_to_uri
137
- translate_id_to_uri.call(id)
138
- else
139
- id = "/#{id}" unless id.start_with? SLASH
140
- unless ActiveFedora.fedora.base_path == SLASH || id.start_with?("#{ActiveFedora.fedora.base_path}/")
141
- id = ActiveFedora.fedora.base_path + id
142
- end
143
- ActiveFedora.fedora.host + id
144
- end
148
+ translate_id_to_uri.call(id)
145
149
  end
146
150
 
147
151
  ##
148
152
  # Transforms a uri into an id
149
153
  # if translate_uri_to_id is set it uses that proc, otherwise just the default
150
154
  def uri_to_id(uri)
151
- if translate_uri_to_id
152
- translate_uri_to_id.call(uri)
153
- else
154
- id = uri.to_s.sub(ActiveFedora.fedora.host + ActiveFedora.fedora.base_path, '')
155
- id.start_with?('/') ? id[1..-1] : id
156
- end
155
+ translate_uri_to_id.call(uri)
157
156
  end
158
157
 
159
158
  ##
@@ -193,33 +192,22 @@ module ActiveFedora
193
192
  end
194
193
  end
195
194
 
196
- def initialize_resource_and_attributes attributes_or_resource_or_url
197
- case attributes_or_resource_or_url
195
+ def initialize_attributes attributes_or_id
196
+ case attributes_or_id
198
197
  when String
199
- @ldp_source = build_ldp_resource(attributes_or_resource_or_url)
200
- @attributes = {}.with_indifferent_access
198
+ attributes = {id: attributes_or_id}.with_indifferent_access
201
199
  when Hash
202
- attributes = attributes_or_resource_or_url
203
-
204
- id = attributes.delete(:id)
205
-
200
+ attributes = attributes_or_id.with_indifferent_access
206
201
  # TODO: Remove when we decide using 'pid' is no longer supported.
207
- if !id && attributes.has_key?(:pid)
202
+ if !attributes.key?(:id) && attributes.key?(:pid)
208
203
  Deprecation.warn Core, 'Initializing with :pid is deprecated and will be removed in active-fedora 10.0. Use :id instead'
209
- id = attributes.delete(:pid)
204
+ attributes[:id] = attributes.delete(:pid)
210
205
  end
211
206
 
212
- attributes = attributes.with_indifferent_access if attributes
213
- @ldp_source = if id
214
- build_ldp_resource(id)
215
- else
216
- build_ldp_resource
217
- end
218
207
  when NilClass
219
- @ldp_source = build_ldp_resource
220
208
  attributes = {}.with_indifferent_access
221
209
  else
222
- raise ArgumentError, "#{attributes_or_resource_or_url.class} is not acceptable"
210
+ raise ArgumentError, "#{attributes_or_id.class} is not acceptable"
223
211
  end
224
212
  return attributes
225
213
  end
@@ -72,4 +72,8 @@ module ActiveFedora #:nodoc:
72
72
  # Transactions are currently incomplete
73
73
  class Rollback < ActiveFedoraError
74
74
  end
75
+
76
+ # Raised when Fedora returns a version without a create date
77
+ class VersionLacksCreateDate < ActiveFedoraError
78
+ end
75
79
  end
@@ -13,8 +13,20 @@ module ActiveFedora
13
13
  @config[:base_path] || '/'
14
14
  end
15
15
 
16
+ def user
17
+ @config[:user]
18
+ end
19
+
20
+ def password
21
+ @config[:password]
22
+ end
23
+
16
24
  def connection
17
- @connection ||= CachingConnection.new(host)
25
+ @connection ||= CachingConnection.new(authorized_connection)
26
+ end
27
+
28
+ def clean_connection
29
+ @clean_connection ||= CleanConnection.new(connection)
18
30
  end
19
31
 
20
32
  def ldp_resource_service
@@ -26,9 +38,9 @@ module ActiveFedora
26
38
 
27
39
  # Call this to create a Container Resource to act as the base path for this connection
28
40
  def init_base_path
29
- connection.get(root_resource_path)
30
- ActiveFedora::Base.logger.info "Attempted to init base path `#{root_resource_path}`, but it already exists" if ActiveFedora::Base.logger
31
- return false
41
+ connection.head(root_resource_path)
42
+ ActiveFedora::Base.logger.info "Attempted to init base path `#{root_resource_path}`, but it already exists" if ActiveFedora::Base.logger
43
+ false
32
44
  rescue Ldp::NotFound
33
45
  if !host.downcase.end_with?("/rest")
34
46
  ActiveFedora::Base.logger.warn "Fedora URL (#{host}) does not end with /rest. This could be a problem. Check your fedora.yml config"
@@ -41,5 +53,11 @@ module ActiveFedora
41
53
  @root_resource_path ||= base_path.sub(SLASH, BLANK)
42
54
  end
43
55
 
56
+ def authorized_connection
57
+ connection = Faraday.new(host)
58
+ connection.basic_auth(user, password)
59
+ connection
60
+ end
61
+
44
62
  end
45
63
  end
@@ -1,11 +1,12 @@
1
1
  module ActiveFedora
2
2
  module FedoraAttributes
3
3
  extend ActiveSupport::Concern
4
+ include InheritableAccessors
4
5
 
5
6
  included do
6
7
  include ActiveTriples::Properties
7
8
  include ActiveTriples::Reflection
8
- delegate :rdf_subject, :get_values, to: :resource
9
+ delegate :rdf_subject, :get_values, :type, to: :resource
9
10
 
10
11
  property :has_model, predicate: ActiveFedora::RDF::Fcrepo::Model.hasModel
11
12
  property :create_date, predicate: ActiveFedora::RDF::Fcrepo4.created
@@ -18,6 +19,8 @@ module ActiveFedora
18
19
  def modified_date
19
20
  super.first
20
21
  end
22
+
23
+ define_inheritable_accessor(:type, :rdf_label)
21
24
  end
22
25
 
23
26
  # Override ActiveTriples method for setting properties
@@ -34,6 +37,12 @@ module ActiveFedora
34
37
  end
35
38
  end
36
39
 
40
+ def id=(id)
41
+ raise "ID has already been set to #{self.id}" if self.id
42
+ @ldp_source = build_ldp_resource(id.to_s)
43
+ end
44
+
45
+
37
46
  # TODO: Remove after we no longer support #pid.
38
47
  def pid
39
48
  Deprecation.warn FedoraAttributes, "#{self.class}#pid is deprecated and will be removed in active-fedora 10.0. Use #{self.class}#id instead."
@@ -56,12 +65,21 @@ module ActiveFedora
56
65
  @resource ||= self.class.resource_class.new(@ldp_source.graph.rdf_subject, @ldp_source.graph)
57
66
  end
58
67
 
68
+ # You can set the URI to use for the rdf_label on ClassMethods.rdf_label, then on
69
+ # the instance, calling rdf_label returns the value of that configured property
70
+ def rdf_label
71
+ resource.rdf_label
72
+ end
73
+
59
74
  module ClassMethods
60
75
  # We make a unique class, because properties belong to a class.
61
76
  # This keeps properties from different objects separate.
77
+ # Since the copy of properties can only happen once, we don't want to invoke it
78
+ # until all properties have been defined.
62
79
  def resource_class
63
80
  @generated_resource_class ||= begin
64
81
  klass = self.const_set(:GeneratedResourceSchema, Class.new(ActiveTriples::Resource))
82
+ klass.configure active_triple_options
65
83
  klass.properties.merge(self.properties).each do |property, config|
66
84
  klass.property(config.term,
67
85
  predicate: config.predicate,
@@ -70,6 +88,12 @@ module ActiveFedora
70
88
  klass
71
89
  end
72
90
  end
91
+
92
+ private
93
+ # @return a Hash of options suitable for passing to ActiveTriples::Base.configure
94
+ def active_triple_options
95
+ { type: type, rdf_label: rdf_label }
96
+ end
73
97
  end
74
98
  end
75
99
  end
@@ -1,3 +1,5 @@
1
+ require 'deprecation'
2
+
1
3
  module ActiveFedora
2
4
 
3
5
  #This class represents a Fedora datastream
@@ -12,8 +14,8 @@ module ActiveFedora
12
14
  define_model_callbacks :save, :create, :destroy
13
15
  define_model_callbacks :initialize, only: :after
14
16
 
15
- # @param parent_or_url [ActiveFedora::Base, String, Hash, NilClass] the parent resource or the URI of this resource
16
- # @param path_name [String] the path partial relative to the resource
17
+ # @param parent_or_url_or_hash [ActiveFedora::Base, String, Hash, NilClass] the parent resource or the URI of this resource
18
+ # @param path [String] the path partial relative to the resource
17
19
  # @param options [Hash]
18
20
  def initialize(parent_or_url_or_hash = nil, path=nil, options={})
19
21
  case parent_or_url_or_hash
@@ -58,14 +60,21 @@ module ActiveFedora
58
60
  ldp_source.subject
59
61
  end
60
62
 
63
+ # If this file have a parent with ldp#contains, we know it is not new.
64
+ # By tracking exists we prevent an unnecessary HEAD request.
61
65
  def new_record?
62
- ldp_source.new?
66
+ !@exists && ldp_source.new?
63
67
  end
64
68
 
65
69
  def uri= uri
66
70
  @ldp_source = Ldp::Resource::BinarySource.new(ldp_connection, uri, '', ActiveFedora.fedora.host + ActiveFedora.fedora.base_path)
67
71
  end
68
72
 
73
+ # If we know the record to exist (parent has LDP:contains), we can avoid unnecessary HEAD requests
74
+ def exists!
75
+ @exists = true
76
+ end
77
+
69
78
  # When restoring from previous versions, we need to reload certain attributes from Fedora
70
79
  def reload
71
80
  return if new_record?
@@ -149,21 +158,6 @@ module ActiveFedora
149
158
  super || content_changed?
150
159
  end
151
160
 
152
-
153
- class << self
154
- def default_attributes
155
- {}
156
- end
157
- end
158
-
159
- def default_attributes
160
- @default_attributes ||= self.class.default_attributes
161
- end
162
-
163
- def default_attributes= attributes
164
- @default_attributes = default_attributes.merge attributes
165
- end
166
-
167
161
  def original_name= name
168
162
  @original_name = name
169
163
  end
@@ -248,11 +242,11 @@ module ActiveFedora
248
242
  ldp_source.content = content
249
243
  if new_record?
250
244
  ldp_source.create do |req|
251
- req.headers = headers
245
+ req.headers.merge!(headers)
252
246
  end
253
247
  else
254
248
  ldp_source.update do |req|
255
- req.headers = headers
249
+ req.headers.merge!(headers)
256
250
  end
257
251
  end
258
252
  reset
@@ -290,12 +284,24 @@ module ActiveFedora
290
284
 
291
285
  module Streaming
292
286
  # @param range [String] the Range HTTP header
293
- # @returns [Stream] an object that responds to each
287
+ # @return [Stream] an object that responds to each
294
288
  def stream(range = nil)
295
289
  uri = URI.parse(self.uri)
296
- headers = {}
297
- headers['Range'] = range if range
298
- FileBody.new(uri, headers)
290
+ FileBody.new(uri, headers(range, authorization_key))
291
+ end
292
+
293
+ # @return [String] current authorization token from Ldp::Client
294
+ def authorization_key
295
+ self.ldp_source.client.http.headers.fetch("Authorization", nil)
296
+ end
297
+
298
+ # @param range [String] from #stream
299
+ # @param key [String] from #authorization_key
300
+ # @return [Hash]
301
+ def headers(range, key, result = Hash.new)
302
+ result["Range"] = range if range
303
+ result["Authorization"] = key if key
304
+ result
299
305
  end
300
306
 
301
307
  class FileBody
@@ -0,0 +1,46 @@
1
+ require 'forwardable'
2
+ module ActiveFedora::Indexing
3
+ # This is a description of how properties should map to indexing strategies
4
+ # e.g. 'creator_name' => <IndexObject behaviors=[:stored_searchable, :facetable]>
5
+ class Map
6
+ extend Forwardable
7
+ def_delegators :@hash, :[], :[]=, :each, :keys
8
+
9
+ def initialize(hash = {})
10
+ @hash = hash
11
+ end
12
+
13
+ def dup
14
+ self.class.new(@hash.deep_dup)
15
+ end
16
+
17
+ # this enables a cleaner API for solr integration
18
+ class IndexObject
19
+ attr_accessor :data_type, :behaviors
20
+
21
+ def initialize(&block)
22
+ @behaviors = []
23
+ @data_type = :string
24
+ yield self if block_given?
25
+ end
26
+
27
+ def as(*args)
28
+ @behaviors = args
29
+ end
30
+
31
+ def type(sym)
32
+ @data_type = sym
33
+ end
34
+
35
+ def dup
36
+ self.class.new do |idx|
37
+ idx.behaviors = @behaviors.dup
38
+ end
39
+ end
40
+
41
+ def defaults
42
+ :noop
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,6 +1,11 @@
1
1
  module ActiveFedora
2
2
  module Indexing
3
3
  extend ActiveSupport::Concern
4
+ extend ActiveSupport::Autoload
5
+
6
+ eager_autoload do
7
+ autoload :Map
8
+ end
4
9
 
5
10
  # Return a Hash representation of this object where keys in the hash are appropriate Solr field names.
6
11
  # @param [Hash] solr_doc (optional) Hash to insert the fields into
@@ -51,6 +56,15 @@ module ActiveFedora
51
56
 
52
57
  module ClassMethods
53
58
 
59
+ # @return ActiveFedora::Indexing::Map
60
+ def index_config
61
+ @index_config ||= if superclass.respond_to?(:index_config)
62
+ superclass.index_config.deep_dup
63
+ else
64
+ ActiveFedora::Indexing::Map.new
65
+ end
66
+ end
67
+
54
68
  def indexer
55
69
  IndexingService
56
70
  end
@@ -0,0 +1,26 @@
1
+ # Similar to ActiveSupport.class_attribute but with a setter that doesn't use the #{name}= syntax
2
+ # This preserves backward compatibility with the API in ActiveTriples
3
+
4
+ module ActiveFedora
5
+ module InheritableAccessors
6
+ extend ActiveSupport::Concern
7
+ module ClassMethods
8
+ def define_inheritable_accessor(*names)
9
+ names.each do |name|
10
+ define_accessor(name, nil)
11
+ end
12
+ end
13
+
14
+ private
15
+ def define_accessor(name, val)
16
+ singleton_class.class_eval do
17
+ remove_possible_method(name)
18
+ define_method(name) do |uri = nil|
19
+ define_accessor(name, uri) if uri
20
+ val
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -62,6 +62,10 @@ module ActiveFedora
62
62
  @values.map {|v| FakeStatement.new(v) }
63
63
  end
64
64
 
65
+ def objects
66
+ @values
67
+ end
68
+
65
69
  class FakeStatement
66
70
  def initialize(value)
67
71
  @value = value
@@ -89,7 +93,7 @@ module ActiveFedora
89
93
  end
90
94
 
91
95
  def reflection(predicate)
92
- @model.outgoing_reflections.find { |key, reflection| reflection.predicate == predicate }.first
96
+ Array(@model.outgoing_reflections.find { |key, reflection| reflection.predicate == predicate }).first
93
97
  end
94
98
  end
95
99
 
@@ -18,10 +18,6 @@ module ActiveFedora
18
18
  @terminology
19
19
  end
20
20
 
21
- def self.default_attributes
22
- super.merge(:mimeType => 'text/xml')
23
- end
24
-
25
21
  def self.decorate_ng_xml(xml)
26
22
  xml.set_terminology terminology_options, &terminology
27
23
  xml.nom!
@@ -62,6 +58,12 @@ module ActiveFedora
62
58
  def respond_to? *args
63
59
  super || self.class.terminology.respond_to?(*args)
64
60
  end
61
+
62
+ protected
63
+
64
+ def default_mime_type
65
+ 'text/xml'
66
+ end
65
67
  end
66
68
  end
67
69
 
@@ -23,8 +23,8 @@ module ActiveFedora
23
23
  # @param [Hash] options
24
24
  # @option options [Boolean] :update_index (true) set false to skip indexing
25
25
  # @return [Boolean] true if save was successful, otherwise false
26
- def save(*args)
27
- create_or_update(*args)
26
+ def save(*options)
27
+ create_or_update(*options)
28
28
  end
29
29
 
30
30
  def save!(*args)
@@ -39,9 +39,10 @@ module ActiveFedora
39
39
 
40
40
  alias update_attributes update
41
41
 
42
- #Deletes a Base object, also deletes the info indexed in Solr, and
43
- #the underlying inner_object. If this object is held in any relationships (ie inbound relationships
44
- #outside of this object it will remove it from those items rels-ext as well
42
+ # Deletes an object from Fedora and deletes the indexed record from Solr.
43
+ # Delete does not run any callbacks, so consider using _destroy_ instead.
44
+ # @param [Hash] opts
45
+ # @option opts [Boolean] :eradicate if passed in, eradicate the tombstone from Fedora
45
46
  def delete(opts = {})
46
47
  return self if new_record?
47
48
 
@@ -68,9 +69,12 @@ module ActiveFedora
68
69
  freeze
69
70
  end
70
71
 
71
- def destroy(*args)
72
+ # Delete the object from Fedora and Solr. Run any before/after/around callbacks for destroy
73
+ # @param [Hash] opts
74
+ # @option opts [Boolean] :eradicate if passed in, eradicate the tombstone from Fedora
75
+ def destroy(*opts)
72
76
  raise ReadOnlyRecord if readonly?
73
- delete(*args)
77
+ delete(*opts)
74
78
  end
75
79
 
76
80
  def eradicate
@@ -26,6 +26,10 @@ module ActiveFedora::RDF
26
26
  def indexer
27
27
  ActiveFedora::RDF::IndexingService
28
28
  end
29
+
30
+ def index_config
31
+ @index_config ||= ActiveFedora::Indexing::Map.new
32
+ end
29
33
  end
30
34
 
31
35
  protected
@@ -7,5 +7,6 @@ module ActiveFedora::RDF
7
7
  property :hasVersionLabel
8
8
  property :lastModified
9
9
  property :status
10
+ property :ServerManaged
10
11
  end
11
12
  end
@@ -4,7 +4,6 @@ module ActiveFedora::RDF
4
4
  attr_reader :object
5
5
 
6
6
  # @param obj [#resource, #rdf_subject] the object to build an solr document for. Its class must respond to 'properties'
7
- # @param prefix_method [Lambda] This method gets the original name of the field and the options passed in. It should return the name of the field in the solr document
8
7
  def initialize(obj)
9
8
  @object = obj
10
9
  end
@@ -22,9 +21,8 @@ module ActiveFedora::RDF
22
21
 
23
22
  def add_assertions(prefix_method, solr_doc = {})
24
23
  fields.each do |field_key, field_info|
25
- values = resource.get_values(field_key)
26
24
  solr_field_key = solr_document_field_name(field_key, prefix_method)
27
- Array(values).each do |val|
25
+ Array(field_info[:values]).each do |val|
28
26
  append_to_solr_doc(solr_doc, solr_field_key, field_info, val)
29
27
  end
30
28
  end
@@ -70,22 +68,31 @@ module ActiveFedora::RDF
70
68
  object.class.properties
71
69
  end
72
70
 
71
+ def index_config
72
+ object.class.index_config
73
+ end
74
+
73
75
  # returns a Hash, e.g.: {field => { values: [], type: :something, behaviors: [] }, ...}
74
76
  def fields
75
77
  field_map = {}.with_indifferent_access
76
78
 
77
- properties.each do |name, config|
78
- type = config[:type]
79
- behaviors = config[:behaviors]
79
+ index_config.each do |name, index_field_config|
80
+ type = index_field_config.data_type
81
+ behaviors = index_field_config.behaviors
80
82
  next unless type and behaviors
81
- next if config[:class_name] && config[:class_name] < ActiveFedora::Base
82
- resource.query(subject: object.rdf_subject, predicate: config[:predicate]).each_statement do |statement|
83
- field_map[name] ||= { values: [], type: type, behaviors: behaviors}
84
- field_map[name][:values] << statement.object.to_s
85
- end
83
+ next if kind_of_af_base?(name)
84
+ field_map[name] = { values: find_values(name), type: type, behaviors: behaviors}
86
85
  end
87
86
  field_map
88
87
  end
89
88
 
89
+ def kind_of_af_base?(name)
90
+ config = properties[name.to_s]
91
+ config && config[:class_name] && config[:class_name] < ActiveFedora::Base
92
+ end
93
+
94
+ def find_values(name)
95
+ object.send(name) || []
96
+ end
90
97
  end
91
98
  end
@@ -3,4 +3,7 @@ class ActiveFedora::RDF::Ldp < RDF::StrictVocabulary("http://www.w3.org/ns/ldp#"
3
3
  # Property definitions
4
4
  property :contains
5
5
  property :member
6
+ property :PreferContainment
7
+ property :PreferEmptyContainer
8
+ property :PreferMembership
6
9
  end
@@ -2,10 +2,6 @@ require 'rdf/ntriples'
2
2
 
3
3
  module ActiveFedora
4
4
  class NtriplesRDFDatastream < RDFDatastream
5
- def self.default_attributes
6
- super.merge(:mimeType => 'text/plain')
7
- end
8
-
9
5
  def serialization_format
10
6
  :ntriples
11
7
  end
@@ -16,6 +16,17 @@ module ActiveFedora
16
16
  @subject_block ||= lambda { |ds| parent_uri(ds) }
17
17
  end
18
18
 
19
+ def property(name, *args, &block)
20
+ super
21
+ add_attribute_indexing_config(name, &block) if block_given?
22
+ end
23
+
24
+ def add_attribute_indexing_config(name, &block)
25
+ Deprecation.warn(RDFDatastream, "Adding indexing to datastreams is deprecated")
26
+ # TODO the hash can be initalized to return on of these
27
+ index_config[name] ||= ActiveFedora::Indexing::Map::IndexObject.new &block
28
+ end
29
+
19
30
  # Trim the last segment off the URI to get the parents uri
20
31
  def parent_uri(ds)
21
32
  m = /^(.*)\/[^\/]*$/.match(ds.uri)
@@ -27,7 +38,7 @@ module ActiveFedora
27
38
  end
28
39
 
29
40
  ##
30
- # @param [Class] an object to set as the resource class, Must be a descendant of
41
+ # @param [Class] klass an object to set as the resource class, Must be a descendant of
31
42
  # ActiveTriples::Resource and include ActiveFedora::RDF::Persistence.
32
43
  #
33
44
  # @return [Class] the object resource class
@@ -152,6 +152,8 @@ module ActiveFedora
152
152
  "#{name.to_s.singularize}_ids"
153
153
  elsif options[:as]
154
154
  "#{options[:as]}_id"
155
+ elsif inverse_of && inverse_of.collection?
156
+ "#{options[:inverse_of].to_s.singularize}_ids"
155
157
  else
156
158
  # This works well if this is a has_many that is the inverse of a belongs_to, but it isn't correct for a has_many that is the invers of a has_and_belongs_to_many
157
159
  active_fedora.name.foreign_key
@@ -292,7 +294,7 @@ module ActiveFedora
292
294
  # returns either false or the inverse association name that it finds.
293
295
  def automatic_inverse_of
294
296
  if can_find_inverse_of_automatically?(self)
295
- inverse_name = ActiveSupport::Inflector.underscore(active_fedora.name).to_sym
297
+ inverse_name = ActiveSupport::Inflector.underscore(options[:as] || active_fedora.name.demodulize).to_sym
296
298
 
297
299
  begin
298
300
  reflection = klass.reflect_on_association(inverse_name)