active-fedora 6.8.0 → 7.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (215) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +15 -5
  4. data/CONTRIBUTING.md +2 -0
  5. data/Gemfile +0 -2
  6. data/History.txt +2 -32
  7. data/README.md +143 -0
  8. data/Rakefile +5 -7
  9. data/active-fedora.gemspec +9 -9
  10. data/gemfiles/rails3.gemfile +11 -0
  11. data/gemfiles/rails4.gemfile +10 -0
  12. data/lib/active_fedora.rb +31 -4
  13. data/lib/active_fedora/association_relation.rb +18 -0
  14. data/lib/active_fedora/associations.rb +38 -171
  15. data/lib/active_fedora/associations/association.rb +163 -0
  16. data/lib/active_fedora/associations/association_scope.rb +39 -0
  17. data/lib/active_fedora/associations/belongs_to_association.rb +47 -25
  18. data/lib/active_fedora/associations/builder/association.rb +55 -0
  19. data/lib/active_fedora/associations/builder/belongs_to.rb +100 -0
  20. data/lib/active_fedora/associations/builder/collection_association.rb +56 -0
  21. data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +30 -0
  22. data/lib/active_fedora/associations/builder/has_many.rb +63 -0
  23. data/lib/active_fedora/associations/builder/singular_association.rb +32 -0
  24. data/lib/active_fedora/associations/{association_collection.rb → collection_association.rb} +203 -53
  25. data/lib/active_fedora/associations/collection_proxy.rb +862 -0
  26. data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +35 -25
  27. data/lib/active_fedora/associations/has_many_association.rb +36 -11
  28. data/lib/active_fedora/associations/singular_association.rb +62 -0
  29. data/lib/active_fedora/attributes.rb +43 -139
  30. data/lib/active_fedora/autosave_association.rb +317 -0
  31. data/lib/active_fedora/base.rb +10 -327
  32. data/lib/active_fedora/callbacks.rb +1 -3
  33. data/lib/active_fedora/content_model.rb +16 -0
  34. data/lib/active_fedora/core.rb +151 -0
  35. data/lib/active_fedora/datastream_attribute.rb +76 -0
  36. data/lib/active_fedora/datastream_hash.rb +8 -13
  37. data/lib/active_fedora/datastreams.rb +39 -26
  38. data/lib/active_fedora/digital_object.rb +2 -2
  39. data/lib/active_fedora/fedora_attributes.rb +45 -0
  40. data/lib/active_fedora/fixture_loader.rb +1 -1
  41. data/lib/active_fedora/indexing.rb +6 -1
  42. data/lib/active_fedora/model.rb +0 -17
  43. data/lib/active_fedora/nested_attributes.rb +2 -2
  44. data/lib/active_fedora/null_relation.rb +7 -0
  45. data/lib/active_fedora/om_datastream.rb +3 -4
  46. data/lib/active_fedora/persistence.rb +41 -29
  47. data/lib/active_fedora/querying.rb +2 -163
  48. data/lib/active_fedora/rdf.rb +1 -0
  49. data/lib/active_fedora/rdf/indexing.rb +67 -0
  50. data/lib/active_fedora/rdf_datastream.rb +2 -50
  51. data/lib/active_fedora/rdf_node.rb +12 -7
  52. data/lib/active_fedora/rdf_node/term_proxy.rb +30 -21
  53. data/lib/active_fedora/rdfxml_rdf_datastream.rb +1 -1
  54. data/lib/active_fedora/reflection.rb +163 -20
  55. data/lib/active_fedora/relation.rb +33 -130
  56. data/lib/active_fedora/relation/calculations.rb +19 -0
  57. data/lib/active_fedora/relation/delegation.rb +22 -0
  58. data/lib/active_fedora/relation/finder_methods.rb +247 -0
  59. data/lib/active_fedora/relation/merger.rb +22 -0
  60. data/lib/active_fedora/relation/query_methods.rb +58 -0
  61. data/lib/active_fedora/relation/spawn_methods.rb +46 -0
  62. data/lib/active_fedora/relationship_graph.rb +0 -2
  63. data/lib/active_fedora/rels_ext_datastream.rb +1 -4
  64. data/lib/active_fedora/rubydora_connection.rb +1 -1
  65. data/lib/active_fedora/scoping.rb +20 -0
  66. data/lib/active_fedora/scoping/default.rb +38 -0
  67. data/lib/active_fedora/scoping/named.rb +32 -0
  68. data/lib/active_fedora/semantic_node.rb +54 -106
  69. data/lib/active_fedora/serialization.rb +19 -0
  70. data/lib/active_fedora/sharding.rb +58 -0
  71. data/lib/active_fedora/solr_digital_object.rb +15 -5
  72. data/lib/active_fedora/solr_instance_loader.rb +1 -1
  73. data/lib/active_fedora/solr_service.rb +1 -1
  74. data/lib/active_fedora/unsaved_digital_object.rb +6 -4
  75. data/lib/active_fedora/version.rb +1 -1
  76. data/lib/tasks/active_fedora.rake +3 -0
  77. data/lib/tasks/active_fedora_dev.rake +6 -5
  78. data/spec/config_helper.rb +14 -14
  79. data/spec/integration/associations_spec.rb +168 -455
  80. data/spec/integration/attributes_spec.rb +12 -11
  81. data/spec/integration/auditable_spec.rb +11 -11
  82. data/spec/integration/autosave_association_spec.rb +25 -0
  83. data/spec/integration/base_spec.rb +163 -163
  84. data/spec/integration/belongs_to_association_spec.rb +166 -0
  85. data/spec/integration/bug_spec.rb +7 -7
  86. data/spec/integration/collection_association_spec.rb +58 -0
  87. data/spec/integration/complex_rdf_datastream_spec.rb +88 -88
  88. data/spec/integration/datastream_collections_spec.rb +69 -69
  89. data/spec/integration/datastream_spec.rb +43 -43
  90. data/spec/integration/datastreams_spec.rb +63 -63
  91. data/spec/integration/delete_all_spec.rb +46 -39
  92. data/spec/integration/fedora_solr_sync_spec.rb +5 -5
  93. data/spec/integration/field_to_solr_name_spec.rb +34 -0
  94. data/spec/integration/full_featured_model_spec.rb +100 -101
  95. data/spec/integration/has_and_belongs_to_many_associations_spec.rb +341 -0
  96. data/spec/integration/has_many_associations_spec.rb +172 -24
  97. data/spec/integration/json_serialization_spec.rb +31 -0
  98. data/spec/integration/load_from_solr_spec.rb +48 -0
  99. data/spec/integration/model_spec.rb +35 -40
  100. data/spec/integration/nested_attribute_spec.rb +42 -43
  101. data/spec/integration/ntriples_datastream_spec.rb +131 -113
  102. data/spec/integration/om_datastream_spec.rb +67 -67
  103. data/spec/integration/persistence_spec.rb +7 -7
  104. data/spec/integration/rdf_nested_attributes_spec.rb +56 -56
  105. data/spec/integration/relation_delegation_spec.rb +26 -25
  106. data/spec/integration/relation_spec.rb +42 -0
  107. data/spec/integration/rels_ext_datastream_spec.rb +20 -20
  108. data/spec/integration/scoped_query_spec.rb +61 -51
  109. data/spec/integration/solr_instance_loader_spec.rb +5 -5
  110. data/spec/integration/solr_service_spec.rb +46 -46
  111. data/spec/samples/hydra-mods_article_datastream.rb +334 -334
  112. data/spec/samples/hydra-rights_metadata_datastream.rb +57 -57
  113. data/spec/samples/marpa-dc_datastream.rb +17 -17
  114. data/spec/samples/models/audio_record.rb +16 -16
  115. data/spec/samples/models/image.rb +2 -2
  116. data/spec/samples/models/mods_article.rb +5 -5
  117. data/spec/samples/models/oral_history.rb +18 -18
  118. data/spec/samples/models/seminar.rb +24 -24
  119. data/spec/samples/models/seminar_audio_file.rb +17 -17
  120. data/spec/samples/oral_history_sample_model.rb +21 -21
  121. data/spec/samples/special_thing.rb +14 -14
  122. data/spec/spec_helper.rb +11 -7
  123. data/spec/support/an_active_model.rb +2 -8
  124. data/spec/support/freeze_mocks.rb +12 -0
  125. data/spec/support/mock_fedora.rb +17 -16
  126. data/spec/unit/active_fedora_spec.rb +58 -60
  127. data/spec/unit/attributes_spec.rb +314 -0
  128. data/spec/unit/base_active_model_spec.rb +28 -27
  129. data/spec/unit/base_cma_spec.rb +5 -5
  130. data/spec/unit/base_datastream_management_spec.rb +27 -27
  131. data/spec/unit/base_extra_spec.rb +76 -48
  132. data/spec/unit/base_spec.rb +277 -348
  133. data/spec/unit/callback_spec.rb +18 -19
  134. data/spec/unit/code_configurator_spec.rb +17 -17
  135. data/spec/unit/config_spec.rb +8 -16
  136. data/spec/unit/content_model_spec.rb +79 -60
  137. data/spec/unit/datastream_collections_spec.rb +229 -229
  138. data/spec/unit/datastream_spec.rb +51 -63
  139. data/spec/unit/datastreams_spec.rb +87 -87
  140. data/spec/unit/file_configurator_spec.rb +217 -217
  141. data/spec/unit/has_and_belongs_to_many_collection_spec.rb +44 -25
  142. data/spec/unit/has_many_collection_spec.rb +26 -8
  143. data/spec/unit/inheritance_spec.rb +13 -12
  144. data/spec/unit/model_spec.rb +39 -45
  145. data/spec/unit/nom_datastream_spec.rb +15 -15
  146. data/spec/unit/ntriples_datastream_spec.rb +123 -118
  147. data/spec/unit/om_datastream_spec.rb +227 -233
  148. data/spec/unit/persistence_spec.rb +34 -15
  149. data/spec/unit/predicates_spec.rb +73 -73
  150. data/spec/unit/property_spec.rb +17 -9
  151. data/spec/unit/qualified_dublin_core_datastream_spec.rb +33 -33
  152. data/spec/unit/query_spec.rb +222 -198
  153. data/spec/unit/rdf_datastream_spec.rb +21 -28
  154. data/spec/unit/rdf_list_nested_attributes_spec.rb +34 -34
  155. data/spec/unit/rdf_list_spec.rb +65 -64
  156. data/spec/unit/rdf_node_spec.rb +7 -7
  157. data/spec/unit/rdf_xml_writer_spec.rb +10 -10
  158. data/spec/unit/rdfxml_rdf_datastream_spec.rb +27 -27
  159. data/spec/unit/relationship_graph_spec.rb +51 -51
  160. data/spec/unit/rels_ext_datastream_spec.rb +68 -74
  161. data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +15 -15
  162. data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +15 -15
  163. data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +15 -15
  164. data/spec/unit/rspec_matchers/match_fedora_datastream_matcher_spec.rb +12 -12
  165. data/spec/unit/rubydora_connection_spec.rb +5 -5
  166. data/spec/unit/semantic_node_spec.rb +48 -107
  167. data/spec/unit/serializers_spec.rb +4 -4
  168. data/spec/unit/service_definitions_spec.rb +26 -26
  169. data/spec/unit/simple_datastream_spec.rb +17 -17
  170. data/spec/unit/solr_config_options_spec.rb +29 -28
  171. data/spec/unit/solr_digital_object_spec.rb +17 -25
  172. data/spec/unit/solr_service_spec.rb +95 -82
  173. data/spec/unit/unsaved_digital_object_spec.rb +24 -23
  174. data/spec/unit/validations_spec.rb +21 -21
  175. metadata +110 -159
  176. data/.rspec +0 -1
  177. data/.rubocop.yml +0 -1
  178. data/.rubocop_todo.yml +0 -938
  179. data/CONSOLE_GETTING_STARTED.textile +0 -1
  180. data/NOKOGIRI_DATASTREAMS.textile +0 -1
  181. data/README.textile +0 -116
  182. data/lib/active_fedora/associations/association_proxy.rb +0 -178
  183. data/lib/active_fedora/delegating.rb +0 -72
  184. data/lib/active_fedora/nokogiri_datastream.rb +0 -11
  185. data/spec/integration/delegating_spec.rb +0 -59
  186. data/spec/rails3_test_app/.gitignore +0 -4
  187. data/spec/rails3_test_app/.rspec +0 -1
  188. data/spec/rails3_test_app/Gemfile +0 -40
  189. data/spec/rails3_test_app/Rakefile +0 -7
  190. data/spec/rails3_test_app/app/controllers/application_controller.rb +0 -3
  191. data/spec/rails3_test_app/app/helpers/application_helper.rb +0 -2
  192. data/spec/rails3_test_app/app/views/layouts/application.html.erb +0 -14
  193. data/spec/rails3_test_app/config.ru +0 -4
  194. data/spec/rails3_test_app/config/application.rb +0 -42
  195. data/spec/rails3_test_app/config/boot.rb +0 -6
  196. data/spec/rails3_test_app/config/database.yml +0 -22
  197. data/spec/rails3_test_app/config/environment.rb +0 -5
  198. data/spec/rails3_test_app/config/environments/development.rb +0 -25
  199. data/spec/rails3_test_app/config/environments/production.rb +0 -49
  200. data/spec/rails3_test_app/config/environments/test.rb +0 -35
  201. data/spec/rails3_test_app/config/initializers/backtrace_silencers.rb +0 -7
  202. data/spec/rails3_test_app/config/initializers/inflections.rb +0 -10
  203. data/spec/rails3_test_app/config/initializers/mime_types.rb +0 -5
  204. data/spec/rails3_test_app/config/initializers/secret_token.rb +0 -7
  205. data/spec/rails3_test_app/config/initializers/session_store.rb +0 -8
  206. data/spec/rails3_test_app/config/locales/en.yml +0 -5
  207. data/spec/rails3_test_app/config/routes.rb +0 -58
  208. data/spec/rails3_test_app/db/seeds.rb +0 -7
  209. data/spec/rails3_test_app/run_tests +0 -3
  210. data/spec/rails3_test_app/script/rails +0 -6
  211. data/spec/rails3_test_app/spec/spec_helper.rb +0 -27
  212. data/spec/rails3_test_app/spec/unit/rails_3_init.rb +0 -15
  213. data/spec/unit/association_proxy_spec.rb +0 -12
  214. data/spec/unit/base_delegate_spec.rb +0 -197
  215. data/spec/unit/base_delegate_to_spec.rb +0 -73
@@ -1,5 +1,3 @@
1
- require 'active_support/core_ext/array/wrap'
2
-
3
1
  module ActiveFedora
4
2
  # = Active Fedora Callbacks, adapted from ActiveRecord
5
3
  #
@@ -234,7 +232,7 @@ module ActiveFedora
234
232
 
235
233
  private
236
234
 
237
- def persist #:nodoc:
235
+ def persist(should_update_index) #:nodoc:
238
236
  run_callbacks(:save) { super }
239
237
  end
240
238
 
@@ -21,6 +21,22 @@ module ActiveFedora
21
21
  obj.relationships(:has_model)
22
22
  end
23
23
 
24
+ def self.best_model_for(obj)
25
+ best_model_match = obj.class unless obj.instance_of? ActiveFedora::Base
26
+
27
+ known_models_for(obj).each do |model_value|
28
+ # If this is of type ActiveFedora::Base, then set to the first found :has_model.
29
+ best_model_match ||= model_value
30
+
31
+ # If there is an inheritance structure, use the most specific case.
32
+ if best_model_match > model_value
33
+ best_model_match = model_value
34
+ end
35
+ end
36
+
37
+ best_model_match
38
+ end
39
+
24
40
  # returns an array of the model classes that are defined in the current
25
41
  # application that the given object asserts (ie. if the object asserts
26
42
  # a StreamingVideo model but the application doesn't define a
@@ -0,0 +1,151 @@
1
+ module ActiveFedora
2
+ module Core
3
+ extend ActiveSupport::Concern
4
+
5
+ attr_reader :inner_object
6
+
7
+ # Constructor. You may supply a custom +:pid+, or we call the Fedora Rest API for the
8
+ # next available Fedora pid, and mark as new object.
9
+ # Also, if +attrs+ does not contain +:pid+ but does contain +:namespace+ it will pass the
10
+ # +:namespace+ value to Fedora::Repository.nextid to generate the next pid available within
11
+ # the given namespace.
12
+ def initialize(attrs = nil)
13
+ attrs = {} if attrs.nil?
14
+ @association_cache = {}
15
+ attributes = attrs.dup
16
+ @inner_object = UnsavedDigitalObject.new(self.class, attributes.delete(:namespace), attributes.delete(:pid))
17
+ self.relationships_loaded = true
18
+ load_datastreams
19
+
20
+ [:new_object,:create_date, :modified_date].each { |k| attributes.delete(k)}
21
+ self.attributes=attributes
22
+ run_callbacks :initialize
23
+ end
24
+
25
+ # Reloads the object from Fedora.
26
+ def reload
27
+ raise ActiveFedora::ObjectNotFoundError, "Can't reload an object that hasn't been saved" unless persisted?
28
+ clear_association_cache
29
+ clear_relationships
30
+ init_with(self.class.find(self.pid).inner_object)
31
+ end
32
+
33
+ # Initialize an empty model object and set the +inner_obj+
34
+ # example:
35
+ #
36
+ # class Post < ActiveFedora::Base
37
+ # has_metadata :name => "properties", :type => ActiveFedora::SimpleDatastream
38
+ # end
39
+ #
40
+ # post = Post.allocate
41
+ # post.init_with(DigitalObject.find(pid))
42
+ # post.properties.title # => 'hello world'
43
+ def init_with(inner_obj)
44
+ @association_cache = {}
45
+ @inner_object = inner_obj
46
+ unless @inner_object.is_a? SolrDigitalObject
47
+ @inner_object.original_class = self.class
48
+ ## Replace existing unchanged datastreams with the definitions found in this class if they have a different type.
49
+ ## Any datastream that is deleted here will cause a reload from fedora, so avoid it whenever possible
50
+ ds_specs.keys.each do |key|
51
+ if @inner_object.datastreams[key] != nil && !@inner_object.datastreams[key].content_changed? && @inner_object.datastreams[key].class != self.class.ds_specs[key][:type]
52
+ @inner_object.datastreams.delete(key)
53
+ end
54
+ end
55
+ end
56
+ load_datastreams
57
+ run_callbacks :find
58
+ run_callbacks :initialize
59
+ self
60
+ end
61
+
62
+ def ==(comparison_object)
63
+ comparison_object.equal?(self) ||
64
+ (comparison_object.instance_of?(self.class) &&
65
+ comparison_object.pid == pid &&
66
+ !comparison_object.new_record?)
67
+ end
68
+
69
+ def clone
70
+ new_object = self.class.create
71
+ clone_into(new_object)
72
+ end
73
+
74
+ # Clone the datastreams from this object into the provided object, while preserving the pid of the provided object
75
+ # @param [Base] new_object clone into this object
76
+ def clone_into(new_object)
77
+ rels = Nokogiri::XML( rels_ext.content)
78
+ rels.xpath("//rdf:Description/@rdf:about").first.value = new_object.internal_uri
79
+ new_object.rels_ext.content = rels.to_xml
80
+
81
+ datastreams.each do |k, v|
82
+ next if k == 'RELS-EXT'
83
+ new_object.datastreams[k].content = v.content
84
+ end
85
+ new_object if new_object.save
86
+ end
87
+
88
+ def pretty_pid
89
+ if self.pid == UnsavedDigitalObject::PLACEHOLDER
90
+ nil
91
+ else
92
+ self.pid
93
+ end
94
+ end
95
+
96
+ # This method adapts the inner_object to a new ActiveFedora::Base implementation
97
+ # This is intended to minimize redundant interactions with Fedora
98
+ def adapt_to(klass)
99
+ unless klass.ancestors.include? ActiveFedora::Base
100
+ raise "Cannot adapt #{self.class.name} to #{klass.name}: Not a ActiveFedora::Base subclass"
101
+ end
102
+ klass.allocate.init_with(inner_object)
103
+ end
104
+
105
+ # Examines the :has_model assertions in the RELS-EXT.
106
+ #
107
+ # If the object is of type ActiveFedora::Base, then use the first :has_model
108
+ # in the RELS-EXT for this object. Due to how the RDF writer works, this is
109
+ # currently just the first alphabetical model.
110
+ #
111
+ # If the object was instantiated with any other class, then use that class
112
+ # as the base of the type the user wants rather than casting to the first
113
+ # :has_model found on the object.
114
+ #
115
+ # In either case, if an extended model of that initial base model of the two
116
+ # cases above exists in the :has_model, then instantiate as that extended
117
+ # model type instead.
118
+ def adapt_to_cmodel
119
+ best_model_match = ActiveFedora::ContentModel.best_model_for(self)
120
+
121
+ self.instance_of?(best_model_match) ? self : self.adapt_to(best_model_match)
122
+ end
123
+
124
+ # ** EXPERIMENTAL **
125
+ # This method returns a new object of the same class, with the internal SolrDigitalObject
126
+ # replaced with an actual DigitalObject.
127
+ def reify
128
+ if self.inner_object.is_a? DigitalObject
129
+ raise "#{self.inspect} is already a full digital object"
130
+ end
131
+ self.class.find self.pid
132
+ end
133
+
134
+ # ** EXPERIMENTAL **
135
+ # This method reinitializes a lightweight, loaded-from-solr object with an actual
136
+ # DigitalObject inside.
137
+ def reify!
138
+ if self.inner_object.is_a? DigitalObject
139
+ raise "#{self.inspect} is already a full digital object"
140
+ end
141
+ self.init_with DigitalObject.find(self.class,self.pid)
142
+ end
143
+
144
+ module ClassMethods
145
+ private
146
+ def relation
147
+ Relation.new(self)
148
+ end
149
+ end
150
+ end
151
+ end
@@ -0,0 +1,76 @@
1
+ module ActiveFedora
2
+ # Represents the mapping between a model attribute and a field in a datastream
3
+ class DatastreamAttribute
4
+
5
+ attr_accessor :dsid, :field, :klass, :at, :reader, :writer, :multiple
6
+
7
+ def initialize(field, dsid, klass, args={})
8
+ self.field = field
9
+ self.dsid = dsid
10
+ self.klass = klass
11
+ self.multiple = args[:multiple].nil? ? false : args[:multiple]
12
+ self.at = args[:at]
13
+
14
+ initialize_reader!
15
+ initialize_writer!
16
+ end
17
+
18
+ # Gives the primary solr name for a column. If there is more than one indexer on the field definition, it gives the first
19
+ def primary_solr_name
20
+ if klass.respond_to?(:primary_solr_name)
21
+ klass.primary_solr_name(dsid, field)
22
+ else
23
+ raise IllegalOperation, "the class '#{klass}' doesn't respond to 'primary_solr_name'"
24
+ end
25
+ end
26
+
27
+ def type
28
+ if klass.respond_to?(:type)
29
+ klass.type(field)
30
+ else
31
+ raise IllegalOperation, "the class '#{klass}' doesn't respond to 'type'"
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def initialize_writer!
38
+ this = self
39
+ self.writer = lambda do |v|
40
+ ds = datastream_for_attribute(this.dsid)
41
+ mark_as_changed(this.field) if value_has_changed?(this.field, v)
42
+ if ds.kind_of?(ActiveFedora::RDFDatastream)
43
+ ds.send("#{this.field}=", v)
44
+ else
45
+ terminology = this.at || [this.field]
46
+ ds.send(:update_indexed_attributes, {terminology => v})
47
+ end
48
+ end
49
+ end
50
+
51
+ def initialize_reader!
52
+ this = self
53
+ self.reader = lambda do |*opts|
54
+ if inner_object.is_a? SolrDigitalObject
55
+ # Look in the cache
56
+ # TODO catch a non-cached error and try fedora.
57
+ inner_object.fetch(this.field)
58
+ else
59
+ # Load from fedora
60
+ ds = datastream_for_attribute(this.dsid)
61
+ if ds.kind_of?(ActiveFedora::RDFDatastream)
62
+ ds.send(this.field)
63
+ else
64
+ terminology = this.at || [this.field]
65
+ if terminology.length == 1 && opts.present?
66
+ ds.send(terminology.first, *opts)
67
+ else
68
+ ds.send(:term_values, *terminology)
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+
75
+ end
76
+ end
@@ -1,14 +1,9 @@
1
- require 'forwardable'
2
-
3
1
  module ActiveFedora
4
- class DatastreamHash
5
- extend Forwardable
6
-
7
- def_delegators :@hash, *(Hash.instance_methods(false))
8
-
9
- def initialize (obj, &block)
2
+ class DatastreamHash < Hash
3
+
4
+ def initialize (obj)
10
5
  @obj = obj
11
- @hash = Hash.new &block
6
+ super()
12
7
  end
13
8
 
14
9
  def [] (key)
@@ -16,12 +11,12 @@ module ActiveFedora
16
11
  ds = Datastream.new(@obj.inner_object, key, :controlGroup=>'X')
17
12
  self[key] = ds
18
13
  end
19
- @hash[key]
14
+ super
20
15
  end
21
16
 
22
17
  def []= (key, val)
23
- @obj.inner_object.datastreams[key]=val
24
- @hash[key]=val
25
- end
18
+ @obj.inner_object.datastreams[key]=val# unless @obj.inner_object.new?
19
+ super
20
+ end
26
21
  end
27
22
  end
@@ -16,7 +16,7 @@ module ActiveFedora
16
16
  end
17
17
 
18
18
  before_save :add_disseminator_location_to_datastreams
19
- before_save :serialize_datastreams
19
+ #before_save :serialize_datastreams
20
20
  end
21
21
 
22
22
  def ds_specs
@@ -38,16 +38,6 @@ module ActiveFedora
38
38
  true
39
39
  end
40
40
 
41
- ## Given a method name, return the best-guess dsid
42
- def corresponding_datastream_name(method_name)
43
- dsid = method_name.to_s
44
- return dsid if datastreams.has_key? dsid
45
- unescaped_name = method_name.to_s.gsub('_', '-')
46
- return unescaped_name if datastreams.has_key? unescaped_name
47
- nil
48
- end
49
-
50
-
51
41
  #
52
42
  # Datastream Management
53
43
  #
@@ -72,7 +62,7 @@ module ActiveFedora
72
62
  end
73
63
 
74
64
  def datastream_from_spec(ds_spec, name)
75
- inner_object.datastream_object_for name, {}, ds_spec
65
+ inner_object.datastream_object_for name, ds_spec
76
66
  end
77
67
 
78
68
  def load_datastreams
@@ -99,10 +89,10 @@ module ActiveFedora
99
89
  datastream.instance_variable_set :@dsid, generate_dsid(prefix)
100
90
  end
101
91
  datastreams[datastream.dsid] = datastream
102
- return datastream.dsid
92
+ datastream.dsid
103
93
  end
104
94
 
105
- #return all datastreams of type ActiveFedora::RDFDatastream or ActiveFedora::NokogiriDatastream
95
+ # @return [Array] all datastreams that return true for `metadata?` and are not Rels-ext
106
96
  def metadata_streams
107
97
  datastreams.select { |k, ds| ds.metadata? }.reject { |k, ds| ds.kind_of?(ActiveFedora::RelsExtDatastream) }.values
108
98
  end
@@ -120,13 +110,6 @@ module ActiveFedora
120
110
  sprintf("%s%i", prefix,suffix)
121
111
  end
122
112
 
123
- # Return the Dublin Core (DC) Datastream. You can also get at this via
124
- # the +datastreams["DC"]+.
125
- def dc
126
- Deprecation.warn(Datastreams, 'dc is deprecated. Consider using Base#datastreams["DC"] instead.', caller)
127
- return datastreams["DC"]
128
- end
129
-
130
113
  # Returns the RELS-EXT Datastream
131
114
  # Tries to grab from in-memory datastreams first
132
115
  # Failing that, attempts to load from Fedora and addst to in-memory datastreams
@@ -161,7 +144,9 @@ module ActiveFedora
161
144
  attrs[:checksumType] = opts[:checksumType] if opts[:checksumType]
162
145
  attrs[:versionable] = opts[:versionable] unless opts[:versionable].nil?
163
146
  ds = create_datastream(self.class.datastream_class_for_name(opts[:dsid]), opts[:dsid], attrs)
164
- add_datastream(ds)
147
+ add_datastream(ds).tap do |dsid|
148
+ self.class.build_datastream_accessor(dsid) unless respond_to? dsid
149
+ end
165
150
  end
166
151
 
167
152
 
@@ -189,10 +174,16 @@ module ActiveFedora
189
174
  end
190
175
 
191
176
  module ClassMethods
192
- #This method is used to specify the details of a datastream.
177
+ # @param [String] dsid the datastream id
178
+ # @returns [Class] the class of the datastream
179
+ def datastream_class_for_name(dsid)
180
+ ds_specs[dsid] ? ds_specs[dsid].fetch(:type, ActiveFedora::Datastream) : ActiveFedora::Datastream
181
+ end
182
+
183
+ # This method is used to specify the details of a datastream.
193
184
  # You can pass the name as the first argument and a hash of options as the second argument
194
185
  # or you can pass the :name as a value in the args hash. Either way, name is required.
195
- # Note that this method doesn't actually execute the block, but stores it , to be executed
186
+ # Note that this method doesn't actually execute the block, but stores it, to be executed
196
187
  # by any the implementation of the datastream(specified as :type)
197
188
  #
198
189
  # @param [Hash] args
@@ -217,8 +208,12 @@ module ActiveFedora
217
208
 
218
209
 
219
210
  spec = {:autocreate => args.fetch(:autocreate, false), :type => args[:type], :label => args.fetch(:label,""), :control_group => args[:control_group], :disseminator => args.fetch(:disseminator,""), :url => args.fetch(:url,""),:block => block}
211
+ name = args[:name]
212
+ raise ArgumentError, "You must provide a name (dsid) for the metadata datastream" unless name
213
+ raise ArgumentError, "You must provide a :type property for the metadata datastream '#{name}'" unless spec[:type]
220
214
  spec[:versionable] = args[:versionable] if args.has_key? :versionable
221
- ds_specs[args[:name]]= spec
215
+ build_datastream_accessor(name)
216
+ ds_specs[name]= spec
222
217
  end
223
218
 
224
219
 
@@ -251,8 +246,26 @@ module ActiveFedora
251
246
  spec = {:autocreate => args.fetch(:autocreate, false), :type => args.fetch(:type,ActiveFedora::Datastream),
252
247
  :label => args.fetch(:label,"File Datastream"), :control_group => args.fetch(:control_group,"M")}
253
248
  spec[:versionable] = args[:versionable] if args.has_key? :versionable
254
- ds_specs[args.fetch(:name, "content")]= spec
249
+ name = args.fetch(:name, "content")
250
+ build_datastream_accessor(name)
251
+ ds_specs[name]= spec
255
252
  end
253
+
254
+ def build_datastream_accessor(dsid)
255
+ name = name_for_dsid(dsid)
256
+ define_method name do
257
+ datastreams[dsid]
258
+ end
259
+ end
260
+
261
+
262
+ private
263
+
264
+ ## Given a dsid return a standard name
265
+ def name_for_dsid(dsid)
266
+ dsid.gsub('-', '_')
267
+ end
268
+
256
269
  end
257
270
 
258
271
  end
@@ -4,10 +4,10 @@ module ActiveFedora
4
4
  attr_accessor :original_class
5
5
 
6
6
  module DatastreamBootstrap
7
- def datastream_object_for dsid, options={}, ds_spec=nil
7
+ def datastream_object_for dsid, ds_spec=nil
8
8
  # ds_spec is nil when called from Rubydora for existing datastreams, so it should not be autocreated
9
9
  ds_spec ||= (original_class.ds_specs[dsid] || {}).merge(:autocreate=>false)
10
- ds = ds_spec.fetch(:type, ActiveFedora::Datastream).new(self, dsid, options)
10
+ ds = ds_spec.fetch(:type, ActiveFedora::Datastream).new(self, dsid)
11
11
  attributes = {}
12
12
  attributes[:asOfDateTime] ||= asOfDateTime if self.respond_to? :asOfDateTime
13
13
  attributes[:dsLabel] = ds_spec[:label] if ds_spec[:label].present?
@@ -0,0 +1,45 @@
1
+ module ActiveFedora
2
+ module FedoraAttributes
3
+
4
+ delegate :state=, :label=, to: :inner_object
5
+
6
+ #return the pid of the Fedora Object
7
+ # if there is no fedora object (loaded from solr) get the instance var
8
+ # TODO make inner_object a proxy that can hold the pid
9
+ def pid
10
+ @inner_object.pid
11
+ end
12
+
13
+ def id ### Needed for the nested form helper
14
+ self.pid
15
+ end
16
+
17
+ #return the owner id
18
+ def owner_id
19
+ Array(@inner_object.ownerId).first
20
+ end
21
+
22
+ def owner_id=(owner_id)
23
+ @inner_object.ownerId=(owner_id)
24
+ end
25
+
26
+ def label
27
+ Array(@inner_object.label).first
28
+ end
29
+
30
+ def state
31
+ Array(@inner_object.state).first
32
+ end
33
+
34
+ #return the create_date of the inner object (unless it's a new object)
35
+ def create_date
36
+ @inner_object.new_record? ? Time.now : Array(@inner_object.createdDate).first
37
+ end
38
+
39
+ #return the modification date of the inner object (unless it's a new object)
40
+ def modified_date
41
+ @inner_object.new_record? ? Time.now : Array(@inner_object.lastModifiedDate).first
42
+ end
43
+
44
+ end
45
+ end