active-fedora 8.7.0 → 9.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (242) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +8 -15
  3. data/Gemfile +5 -5
  4. data/History.txt +0 -80
  5. data/README.md +1 -0
  6. data/Rakefile +0 -3
  7. data/active-fedora.gemspec +8 -7
  8. data/config/fedora.yml +5 -4
  9. data/config/predicate_mappings.yml +5 -5
  10. data/gemfiles/rails4.1.gemfile +10 -0
  11. data/gemfiles/rails4.2.beta.gemfile +10 -0
  12. data/lib/active_fedora.rb +151 -117
  13. data/lib/active_fedora/associations.rb +47 -15
  14. data/lib/active_fedora/associations/association.rb +29 -8
  15. data/lib/active_fedora/associations/association_scope.rb +5 -5
  16. data/lib/active_fedora/associations/belongs_to_association.rb +20 -63
  17. data/lib/active_fedora/associations/builder/association.rb +61 -25
  18. data/lib/active_fedora/associations/builder/belongs_to.rb +7 -94
  19. data/lib/active_fedora/associations/builder/collection_association.rb +11 -43
  20. data/lib/active_fedora/associations/builder/contains.rb +28 -0
  21. data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +13 -3
  22. data/lib/active_fedora/associations/builder/has_many.rb +16 -10
  23. data/lib/active_fedora/associations/builder/property.rb +14 -0
  24. data/lib/active_fedora/associations/builder/singular_association.rb +14 -18
  25. data/lib/active_fedora/associations/builder/singular_property.rb +12 -0
  26. data/lib/active_fedora/associations/collection_association.rb +57 -80
  27. data/lib/active_fedora/associations/contains_association.rb +50 -0
  28. data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +44 -24
  29. data/lib/active_fedora/associations/has_many_association.rb +46 -14
  30. data/lib/active_fedora/associations/rdf.rb +86 -0
  31. data/lib/active_fedora/associations/singular_association.rb +4 -8
  32. data/lib/active_fedora/associations/singular_rdf.rb +15 -0
  33. data/lib/active_fedora/attached_files.rb +195 -0
  34. data/lib/active_fedora/attribute_methods.rb +122 -0
  35. data/lib/active_fedora/attribute_methods/dirty.rb +16 -0
  36. data/lib/active_fedora/attribute_methods/read.rb +61 -0
  37. data/lib/active_fedora/attribute_methods/write.rb +47 -0
  38. data/lib/active_fedora/attributes.rb +93 -44
  39. data/lib/active_fedora/attributes/primary_key.rb +12 -0
  40. data/lib/active_fedora/autosave_association.rb +2 -2
  41. data/lib/active_fedora/base.rb +16 -15
  42. data/lib/active_fedora/callbacks.rb +7 -7
  43. data/lib/active_fedora/change_set.rb +34 -0
  44. data/lib/active_fedora/cleaner.rb +62 -0
  45. data/lib/active_fedora/config.rb +4 -22
  46. data/lib/active_fedora/core.rb +173 -99
  47. data/lib/active_fedora/datastream.rb +4 -117
  48. data/lib/active_fedora/datastreams.rb +2 -263
  49. data/lib/active_fedora/datastreams/nokogiri_datastreams.rb +28 -51
  50. data/lib/active_fedora/{datastream_attribute.rb → delegated_attribute.rb} +57 -26
  51. data/lib/active_fedora/errors.rb +61 -0
  52. data/lib/active_fedora/fedora.rb +19 -0
  53. data/lib/active_fedora/fedora_attributes.rb +58 -26
  54. data/lib/active_fedora/file.rb +318 -0
  55. data/lib/active_fedora/file_configurator.rb +32 -32
  56. data/lib/active_fedora/file_path_builder.rb +24 -0
  57. data/lib/active_fedora/files_hash.rb +82 -0
  58. data/lib/active_fedora/fixity_service.rb +40 -0
  59. data/lib/active_fedora/indexing.rb +55 -82
  60. data/lib/active_fedora/indexing_service.rb +70 -0
  61. data/lib/active_fedora/ldp_resource.rb +26 -0
  62. data/lib/active_fedora/loadable_from_json.rb +112 -0
  63. data/lib/active_fedora/model.rb +5 -19
  64. data/lib/active_fedora/nested_attributes.rb +5 -6
  65. data/lib/active_fedora/nom_datastream.rb +15 -25
  66. data/lib/active_fedora/om_datastream.rb +26 -197
  67. data/lib/active_fedora/persistence.rb +95 -71
  68. data/lib/active_fedora/predicates.rb +4 -4
  69. data/lib/active_fedora/qualified_dublin_core_datastream.rb +17 -18
  70. data/lib/active_fedora/querying.rb +3 -4
  71. data/lib/active_fedora/railtie.rb +3 -6
  72. data/lib/active_fedora/rdf.rb +3 -1
  73. data/lib/active_fedora/rdf/datastream_indexing.rb +11 -0
  74. data/lib/active_fedora/rdf/fcrepo.rb +10 -324
  75. data/lib/active_fedora/rdf/indexing.rb +20 -16
  76. data/lib/active_fedora/rdf/ldp.rb +6 -0
  77. data/lib/active_fedora/rdf/ntriples_rdf_datastream.rb +1 -1
  78. data/lib/active_fedora/rdf/persistence.rb +5 -6
  79. data/lib/active_fedora/rdf/rdf_datastream.rb +44 -37
  80. data/lib/active_fedora/rdf/rdfxml_datastream.rb +13 -0
  81. data/lib/active_fedora/rdf/rels_ext.rb +26 -0
  82. data/lib/active_fedora/reflection.rb +256 -199
  83. data/lib/active_fedora/relation.rb +18 -6
  84. data/lib/active_fedora/relation/finder_methods.rb +69 -38
  85. data/lib/active_fedora/relation/query_methods.rb +7 -3
  86. data/lib/active_fedora/rspec_matchers/belong_to_associated_active_fedora_object_matcher.rb +7 -7
  87. data/lib/active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher.rb +8 -8
  88. data/lib/active_fedora/rspec_matchers/have_predicate_matcher.rb +9 -11
  89. data/lib/active_fedora/simple_datastream.rb +18 -13
  90. data/lib/active_fedora/solr_instance_loader.rb +18 -38
  91. data/lib/active_fedora/solr_service.rb +37 -20
  92. data/lib/active_fedora/sparql_insert.rb +45 -0
  93. data/lib/active_fedora/test_support.rb +1 -22
  94. data/lib/active_fedora/version.rb +1 -1
  95. data/lib/active_fedora/versionable.rb +90 -0
  96. data/lib/active_fedora/with_metadata.rb +37 -0
  97. data/lib/active_fedora/with_metadata/metadata_node.rb +70 -0
  98. data/lib/generators/active_fedora/config/config_generator.rb +0 -1
  99. data/lib/generators/active_fedora/config/solr/solr_generator.rb +1 -1
  100. data/lib/generators/active_fedora/model/model_generator.rb +5 -5
  101. data/lib/generators/active_fedora/model/templates/datastream_spec.rb.erb +1 -1
  102. data/lib/generators/active_fedora/model/templates/model_spec.rb.erb +2 -2
  103. data/lib/tasks/active_fedora_dev.rake +21 -27
  104. data/spec/config_helper.rb +1 -1
  105. data/spec/fixtures/mixed_rdf_descMetadata.nt +6 -6
  106. data/spec/fixtures/rails_root/config/predicate_mappings.yml +3 -19
  107. data/spec/fixtures/solr_rdf_descMetadata.nt +6 -6
  108. data/spec/integration/associations_spec.rb +133 -153
  109. data/spec/integration/attached_files_spec.rb +164 -0
  110. data/spec/integration/attributes_spec.rb +73 -12
  111. data/spec/integration/autosave_association_spec.rb +3 -3
  112. data/spec/integration/base_spec.rb +57 -351
  113. data/spec/integration/belongs_to_association_spec.rb +86 -76
  114. data/spec/integration/bug_spec.rb +3 -3
  115. data/spec/integration/collection_association_spec.rb +4 -4
  116. data/spec/integration/complex_rdf_datastream_spec.rb +54 -56
  117. data/spec/integration/delete_all_spec.rb +18 -15
  118. data/spec/integration/eradicate_spec.rb +54 -0
  119. data/spec/integration/fedora_solr_sync_spec.rb +7 -5
  120. data/spec/integration/field_to_solr_name_spec.rb +5 -5
  121. data/spec/integration/file_fixity_spec.rb +40 -0
  122. data/spec/integration/file_spec.rb +122 -0
  123. data/spec/integration/full_featured_model_spec.rb +53 -63
  124. data/spec/integration/has_and_belongs_to_many_associations_spec.rb +141 -114
  125. data/spec/integration/has_many_associations_spec.rb +142 -64
  126. data/spec/integration/json_serialization_spec.rb +50 -8
  127. data/spec/integration/model_spec.rb +12 -29
  128. data/spec/integration/nested_attribute_spec.rb +28 -20
  129. data/spec/integration/ntriples_datastream_spec.rb +60 -57
  130. data/spec/integration/om_datastream_spec.rb +51 -140
  131. data/spec/integration/rdf_nested_attributes_spec.rb +16 -14
  132. data/spec/integration/relation_delegation_spec.rb +7 -9
  133. data/spec/integration/relation_spec.rb +9 -7
  134. data/spec/integration/scoped_query_spec.rb +26 -26
  135. data/spec/integration/solr_instance_loader_spec.rb +69 -53
  136. data/spec/integration/solr_service_spec.rb +12 -73
  137. data/spec/integration/versionable_spec.rb +477 -0
  138. data/spec/integration/with_metadata_spec.rb +52 -0
  139. data/spec/samples/hydra-mods_article_datastream.rb +10 -6
  140. data/spec/samples/models/mods_article.rb +6 -2
  141. data/spec/samples/oral_history_sample.xml +1 -1
  142. data/spec/samples/oral_history_xml.xml +1 -1
  143. data/spec/samples/special_thing.rb +3 -3
  144. data/spec/spec_helper.rb +22 -12
  145. data/spec/support/an_active_model.rb +3 -7
  146. data/spec/unit/active_fedora_spec.rb +20 -17
  147. data/spec/unit/attached_files_spec.rb +203 -0
  148. data/spec/unit/attributes_spec.rb +286 -207
  149. data/spec/unit/base_active_model_spec.rb +8 -8
  150. data/spec/unit/base_datastream_management_spec.rb +11 -24
  151. data/spec/unit/base_extra_spec.rb +17 -67
  152. data/spec/unit/base_spec.rb +163 -428
  153. data/spec/unit/builder/has_and_belongs_to_many_spec.rb +2 -2
  154. data/spec/unit/callback_spec.rb +38 -23
  155. data/spec/unit/change_set_spec.rb +46 -0
  156. data/spec/unit/code_configurator_spec.rb +5 -5
  157. data/spec/unit/config_spec.rb +9 -14
  158. data/spec/unit/core_spec.rb +59 -8
  159. data/spec/unit/file_configurator_spec.rb +55 -53
  160. data/spec/unit/file_path_builder_spec.rb +18 -0
  161. data/spec/unit/file_spec.rb +221 -0
  162. data/spec/unit/files_hash_spec.rb +53 -0
  163. data/spec/unit/fixity_service_spec.rb +34 -0
  164. data/spec/unit/has_and_belongs_to_many_association_spec.rb +134 -0
  165. data/spec/unit/has_many_association_spec.rb +51 -0
  166. data/spec/unit/indexing_service_spec.rb +23 -0
  167. data/spec/unit/indexing_spec.rb +26 -0
  168. data/spec/unit/inheritance_spec.rb +9 -10
  169. data/spec/unit/model_spec.rb +15 -33
  170. data/spec/unit/nom_datastream_spec.rb +13 -10
  171. data/spec/unit/ntriples_datastream_spec.rb +81 -96
  172. data/spec/unit/om_datastream_spec.rb +137 -227
  173. data/spec/unit/persistence_spec.rb +28 -34
  174. data/spec/unit/predicates_spec.rb +29 -29
  175. data/spec/unit/property_spec.rb +1 -3
  176. data/spec/unit/qualified_dublin_core_datastream_spec.rb +27 -32
  177. data/spec/unit/query_spec.rb +116 -149
  178. data/spec/unit/rdf_datastream_spec.rb +25 -43
  179. data/spec/unit/rdf_resource_datastream_spec.rb +24 -123
  180. data/spec/unit/{rdfxml_rdf_datastream_spec.rb → rdfxml_datastream_spec.rb} +21 -25
  181. data/spec/unit/readonly_spec.rb +23 -0
  182. data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +6 -6
  183. data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +6 -6
  184. data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +6 -6
  185. data/spec/unit/serializers_spec.rb +1 -1
  186. data/spec/unit/simple_datastream_spec.rb +12 -23
  187. data/spec/unit/solr_config_options_spec.rb +14 -17
  188. data/spec/unit/solr_service_spec.rb +38 -77
  189. data/spec/unit/sparql_insert_spec.rb +32 -0
  190. data/spec/unit/validations_spec.rb +8 -11
  191. metadata +96 -121
  192. data/lib/active_fedora/auditable.rb +0 -9
  193. data/lib/active_fedora/content_model.rb +0 -70
  194. data/lib/active_fedora/datastream_collections.rb +0 -302
  195. data/lib/active_fedora/datastream_hash.rb +0 -35
  196. data/lib/active_fedora/digital_object.rb +0 -55
  197. data/lib/active_fedora/fixture_exporter.rb +0 -33
  198. data/lib/active_fedora/fixture_loader.rb +0 -48
  199. data/lib/active_fedora/rdf/identifiable.rb +0 -66
  200. data/lib/active_fedora/rdf/project_hydra.rb +0 -12
  201. data/lib/active_fedora/rdf/rdfxml_rdf_datastream.rb +0 -13
  202. data/lib/active_fedora/rdf_xml_writer.rb +0 -49
  203. data/lib/active_fedora/relationship_graph.rb +0 -101
  204. data/lib/active_fedora/reload_on_save.rb +0 -16
  205. data/lib/active_fedora/rels_ext_datastream.rb +0 -100
  206. data/lib/active_fedora/rspec_matchers/match_fedora_datastream_matcher.rb +0 -41
  207. data/lib/active_fedora/rubydora_connection.rb +0 -35
  208. data/lib/active_fedora/semantic_node.rb +0 -164
  209. data/lib/active_fedora/service_definitions.rb +0 -88
  210. data/lib/active_fedora/sharding.rb +0 -58
  211. data/lib/active_fedora/solr_digital_object.rb +0 -68
  212. data/lib/active_fedora/unsaved_digital_object.rb +0 -58
  213. data/lib/generators/active_fedora/config/fedora/fedora_generator.rb +0 -12
  214. data/lib/generators/active_fedora/config/fedora/templates/fedora.yml +0 -38
  215. data/lib/generators/active_fedora/config/fedora/templates/fedora_conf/conf/development/fedora.fcfg +0 -953
  216. data/lib/generators/active_fedora/config/fedora/templates/fedora_conf/conf/test/fedora.fcfg +0 -953
  217. data/lib/tasks/active_fedora.rake +0 -83
  218. data/spec/fixtures/sharded_fedora.yml +0 -11
  219. data/spec/integration/auditable_spec.rb +0 -29
  220. data/spec/integration/datastream_collections_spec.rb +0 -127
  221. data/spec/integration/datastream_spec.rb +0 -90
  222. data/spec/integration/datastreams_spec.rb +0 -173
  223. data/spec/integration/load_from_solr_spec.rb +0 -66
  224. data/spec/integration/rels_ext_datastream_spec.rb +0 -82
  225. data/spec/support/mock_fedora.rb +0 -44
  226. data/spec/unit/content_model_spec.rb +0 -86
  227. data/spec/unit/datastream_collections_spec.rb +0 -420
  228. data/spec/unit/datastream_spec.rb +0 -83
  229. data/spec/unit/datastreams_spec.rb +0 -243
  230. data/spec/unit/has_and_belongs_to_many_collection_spec.rb +0 -96
  231. data/spec/unit/has_many_collection_spec.rb +0 -35
  232. data/spec/unit/rdf_vocab_spec.rb +0 -30
  233. data/spec/unit/rdf_xml_writer_spec.rb +0 -63
  234. data/spec/unit/relationship_graph_spec.rb +0 -115
  235. data/spec/unit/reload_on_save_spec.rb +0 -24
  236. data/spec/unit/rels_ext_datastream_spec.rb +0 -170
  237. data/spec/unit/rspec_matchers/match_fedora_datastream_matcher_spec.rb +0 -44
  238. data/spec/unit/rubydora_connection_spec.rb +0 -12
  239. data/spec/unit/semantic_node_spec.rb +0 -112
  240. data/spec/unit/service_definitions_spec.rb +0 -63
  241. data/spec/unit/solr_digital_object_spec.rb +0 -97
  242. data/spec/unit/unsaved_digital_object_spec.rb +0 -48
@@ -1,41 +0,0 @@
1
- # RSpec matcher to spec delegations.
2
-
3
- RSpec::Matchers.define :match_fedora_datastream do |method|
4
- match do |object|
5
- @method = method
6
- @object = object
7
- if @expected_xml.nil?
8
- raise(
9
- ArgumentError,
10
- "match_fedora_datastream(<datastream_name>).with(<expected_xml>)"
11
- )
12
- end
13
- expected = Nokogiri::XML(@expected_xml)
14
-
15
- base_url = ActiveFedora.config.credentials[:url]
16
- @fedora_datastream_url = File.join(
17
- base_url, 'objects', @object.pid.to_s,'datastreams', @method, 'content'
18
- )
19
-
20
- response = RestClient.get(@fedora_datastream_url)
21
-
22
- actual = Nokogiri::XML(response.body)
23
-
24
- EquivalentXml.equivalent?(expected, actual, :normalize_whitespace => true)
25
- end
26
-
27
- chain(:with) { |expected_xml| @expected_xml = expected_xml }
28
-
29
- description do
30
- "#{@object.class} PID=#{@object.pid} datastream: #{@method.inspect} matches Fedora"
31
- end
32
-
33
- failure_message_for_should do |text|
34
- "expected #{@object.class} PID=#{@object.pid} datastream: #{@method.inspect} to match Fedora"
35
- end
36
-
37
- failure_message_for_should_not do |text|
38
- "expected #{@object.class} PID=#{@object.pid} datastream: #{@method.inspect} to NOT match Fedora"
39
- end
40
-
41
- end
@@ -1,35 +0,0 @@
1
- require 'rubydora'
2
-
3
- module ActiveFedora
4
- class RubydoraConnection
5
-
6
- attr_accessor :options, :connection
7
-
8
- def initialize(params={})
9
- params = params.dup
10
- self.options = params
11
- connect
12
- end
13
-
14
- def connect(force=false)
15
- return unless @connection.nil? or force
16
- @connection = Rubydora.connect options
17
-
18
- Rubydora::Transaction.after_rollback do |options|
19
- begin
20
- case options[:method]
21
- when :ingest
22
- solr = ActiveFedora::SolrService.instance.conn
23
- solr.delete_by_id(options[:pid])
24
- solr.commit
25
- else
26
- ActiveFedora::Base.find(options[:pid]).update_index
27
- end
28
- rescue
29
- # no-op
30
- end
31
-
32
- end
33
- end
34
- end
35
- end
@@ -1,164 +0,0 @@
1
- module ActiveFedora
2
- module SemanticNode
3
- extend ActiveSupport::Concern
4
-
5
- attr_accessor :relationships_loaded
6
- attr_accessor :load_from_solr, :subject
7
-
8
- def assert_kind_of(n, o,t)
9
- raise "Assertion failure: #{n}: #{o} is not of type #{t}" unless o.kind_of?(t)
10
- end
11
-
12
- def clear_relationships
13
- @relationships_loaded = false
14
- @object_relations = nil
15
- end
16
-
17
- def object_relations
18
- load_relationships if !relationships_loaded
19
- @object_relations ||= RelationshipGraph.new
20
- end
21
-
22
- def relationships_are_dirty?
23
- object_relations.dirty
24
- end
25
- alias relationships_are_dirty relationships_are_dirty?
26
-
27
- def relationships_are_not_dirty!
28
- object_relations.dirty = false
29
- end
30
-
31
- def relationships=(xml)
32
- ::RDF::RDFXML::Reader.new(xml) do |reader|
33
- reader.each_statement do |statement|
34
- literal = statement.object.kind_of?(::RDF::Literal)
35
- object = literal ? statement.object.value : statement.object.to_str
36
- object_relations.add(statement.predicate, object, literal)
37
- end
38
- end
39
- # Adding the relationships to the graph causes the graph to be marked as dirty,
40
- # so now we assert that the graph is in sync
41
- relationships_are_not_dirty!
42
- end
43
-
44
- # Add a relationship to the Object.
45
- # @param [Symbol, String] predicate
46
- # @param [URI, ActiveFedora::Base] target Either a string URI or an object that is a kind of ActiveFedora::Base
47
- # TODO is target ever a AF::Base anymore?
48
- def add_relationship(predicate, target, literal=false)
49
- #raise ArgumentError, "predicate must be a symbol. You provided `#{predicate.inspect}'" unless predicate.class.in?([Symbol, String])
50
- object_relations.add(predicate, target, literal)
51
- rels_ext.content_will_change! if object_relations.dirty
52
- end
53
-
54
- # Clears all relationships with the specified predicate
55
- # @param predicate
56
- def clear_relationship(predicate)
57
- relationships(predicate).each do |target|
58
- object_relations.delete(predicate, target)
59
- end
60
- rels_ext.content_will_change! if object_relations.dirty
61
- end
62
-
63
- # Checks that this object is matches the model class passed in.
64
- # It requires two steps to pass to return true
65
- # 1. It has a hasModel relationship of the same model
66
- # 2. kind_of? returns true for the model passed in
67
- # This method can most often be used to detect if an object from Fedora that was created
68
- # with a different model was then used to populate this object.
69
- # @param [Class] model_class the model class name to check if an object conforms_to that model
70
- # @return [Boolean] true if this object conforms to the given model name
71
- def conforms_to?(model_class)
72
- if self.kind_of?(model_class)
73
- #check has model and class match
74
- mod = relationships.first(:predicate=>Predicates.find_graph_predicate(:has_model))
75
- if mod
76
- expected = self.class.to_class_uri
77
- if mod.object.to_s == expected
78
- return true
79
- else
80
- raise "has_model relationship check failed for model #{model_class} raising exception, expected: '#{expected}' actual: '#{mod.object.to_s}'"
81
- end
82
- else
83
- raise "has_model relationship does not exist for model #{model_class} check raising exception"
84
- end
85
- else
86
- raise "kind_of? check failed for model #{model_class}, actual #{self.class} raising exception"
87
- end
88
- return false
89
- end
90
-
91
- #
92
- # Remove a Rels-Ext relationship from the Object.
93
- # @param predicate
94
- # @param obj Either a string URI or an object that responds to .pid
95
- def remove_relationship(predicate, obj, literal=false)
96
- object_relations.delete(predicate, obj)
97
- object_relations.dirty = true
98
- rels_ext.content_will_change!
99
- end
100
-
101
- # If no arguments are supplied, return the whole RDF::Graph.
102
- # if a predicate is supplied as a parameter, then it returns the result of quering the graph with that predicate
103
- def relationships(*args)
104
- load_relationships unless relationships_loaded
105
-
106
- if args.empty?
107
- raise "Must have internal_uri" unless internal_uri
108
- return object_relations.to_graph(internal_uri)
109
- end
110
- rels = object_relations[args.first] || []
111
- rels.map {|o| o.respond_to?(:internal_uri) ? o.internal_uri : o }.compact #TODO, could just return the object
112
- end
113
-
114
- def load_relationships
115
- @relationships_loaded = true
116
- content = rels_ext.content
117
- return unless content.present?
118
- RelsExtDatastream.from_xml content, rels_ext
119
- end
120
-
121
- def ids_for_outbound(predicate)
122
- (object_relations[predicate] || []).map do |o|
123
- o = o.to_s if o.kind_of? ::RDF::Literal
124
- o.kind_of?(String) ? self.class.pid_from_uri(o) : o.pid
125
- end
126
- end
127
-
128
- # @return [String] the internal fedora URI
129
- def internal_uri
130
- self.class.internal_uri(pid)
131
- end
132
-
133
- module ClassMethods
134
- # Returns a suitable uri object for :has_model
135
- # Should reverse Model#from_class_uri
136
- def to_class_uri(attrs = {})
137
- if self.respond_to? :pid_suffix
138
- pid_suffix = self.pid_suffix
139
- else
140
- pid_suffix = attrs.fetch(:pid_suffix, ContentModel::CMODEL_PID_SUFFIX)
141
- end
142
- if self.respond_to? :pid_namespace
143
- namespace = self.pid_namespace
144
- else
145
- namespace = attrs.fetch(:namespace, ContentModel::CMODEL_NAMESPACE)
146
- end
147
- "info:fedora/#{namespace}:#{ContentModel.sanitized_class_name(self)}#{pid_suffix}"
148
- end
149
-
150
- # @param [String] pid the fedora object identifier
151
- # @return [String] a URI represented as a string
152
- def internal_uri(pid)
153
- "info:fedora/#{pid}"
154
- end
155
-
156
- # @param [String] uri a uri (as a string)
157
- # @return [String] the pid component of the URI
158
- def pid_from_uri(uri)
159
- uri.gsub("info:fedora/", "")
160
- end
161
-
162
- end
163
- end
164
- end
@@ -1,88 +0,0 @@
1
- module ActiveFedora
2
- module ServiceDefinitions
3
- def self.included(mod)
4
- # check that it's an AF base
5
- if mod.ancestors.include? ActiveFedora::Base
6
- mod.extend(ClassMethods)
7
- model_uri = mod.to_class_uri
8
- # load ContentModel, pull Sdef pointers
9
- begin
10
- cmodel = ActiveFedora::ContentModel.find(mod.to_class_uri)
11
- sdef_pids = cmodel.ids_for_outbound(:has_service).collect { |uri|
12
- uri.split('/')[-1]
13
- }
14
- rescue
15
- sdef_pids = []
16
- end
17
- unless sdef_pids.include? "fedora-system:3"
18
- sdef_pids << "fedora-system:3"
19
- end
20
- sdef_pids.each { |sdef_pid| mod.has_service_definition sdef_pid }
21
- end
22
- end
23
- def self.sdef_config
24
- @@methods ||= begin
25
- if defined? Rails
26
- config_path = Rails.root.join('config','service_mappings.yml')
27
- else
28
- config_path = 'config/service_mappings.yml'
29
- end
30
- YAML::load(File.open(config_path))[:service_mapping]
31
- end
32
- @@methods
33
- end
34
- def self.lookup_method(sdef_uri, method_name)
35
- sdef_pid = sdef_uri.split('/')[-1]
36
- begin
37
- sdef = sdef_config[sdef_pid]
38
- return nil unless sdef
39
- result = nil
40
- sdef.each { |key, value| result = key if method_name == value }
41
- rescue
42
- return nil
43
- end
44
- return result
45
- end
46
-
47
- module ClassMethods
48
- def sdef_pids
49
- @sdef_pids ||= []
50
- end
51
- def has_service_definition sdef_uri
52
- sdef_pid = sdef_uri.split('/')[-1]
53
- unless sdef_pids.include? sdef_pid
54
- self.add_sdef_methods! sdef_pid
55
- sdef_pids << sdef_pid
56
- end
57
- end
58
- # iterate over SDef pointers, identify symbols in yaml map
59
- # inject methods by symbol key
60
- def add_sdef_methods! sdef_pid
61
- unless sdef_pid == "fedora-system:3"
62
- content = ActiveFedora::Base.connection_for_pid(sdef_pid).datastream_dissemination(:pid=>sdef_pid, :dsid=>"METHODMAP")
63
- method_map = Nokogiri::XML.parse(content)
64
- methods = method_map.xpath('//fmm:Method').collect { |method|
65
- method["operationName"]
66
- }
67
- else
68
- methods = ["viewObjectProfile","viewMethodIndex","viewItemIndex","viewDublinCore"]
69
- end
70
- methods.each { |method|
71
- add_method!(sdef_pid, method)
72
- }
73
- end
74
- def add_method!(sdef_pid, method_name)
75
- # find method_key
76
- method_key = ServiceDefinitions.lookup_method(sdef_pid, method_name)
77
- if method_key and not method_defined? method_key
78
- define_method(method_key) { |*args, &block|
79
- opts = args[0] || {}
80
- opts = opts.merge({:pid => pid, :sdef => sdef_pid, :method => method_name })
81
- # dispatch to the dissemination method on restAPI client
82
- ActiveFedora::Base.connection_for_pid(pid).dissemination opts, &block
83
- }
84
- end
85
- end
86
- end
87
- end
88
- end
@@ -1,58 +0,0 @@
1
- module ActiveFedora
2
- module Sharding
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- class_attribute :fedora_connection
7
- self.fedora_connection = {}
8
- end
9
-
10
- module ClassMethods
11
- # Uses {#shard_index} to find or create the rubydora connection for this pid
12
- # @param [String] pid the identifier of the object to get the connection for
13
- # @return [Rubydora::Repository] The repository that the identifier exists in.
14
- def connection_for_pid(pid)
15
- idx = shard_index(pid)
16
- unless fedora_connection.has_key? idx
17
- if ActiveFedora.config.sharded?
18
- fedora_connection[idx] = RubydoraConnection.new(ActiveFedora.config.credentials[idx])
19
- else
20
- fedora_connection[idx] = RubydoraConnection.new(ActiveFedora.config.credentials)
21
- end
22
- end
23
- fedora_connection[idx].connection
24
- end
25
-
26
- # This is where your sharding strategy is implemented -- it's how we figure out which shard an object will be (or was) written to.
27
- # Given a pid, it decides which shard that pid will be written to (and thus retrieved from).
28
- # For a given pid, as long as your shard configuration remains the same it will always return the same value.
29
- # If you're not using sharding, this will always return 0, meaning use the first/only Fedora Repository in your configuration.
30
- # Default strategy runs a modulo of the md5 of the pid against the number of shards.
31
- # If you want to use a different sharding strategy, override this method. Make sure that it will always return the same value for a given pid and shard configuration.
32
- #@return [Integer] the index of the shard this object is stored in
33
- def shard_index(pid)
34
- if ActiveFedora.config.sharded?
35
- Digest::MD5.hexdigest(pid).hex % ActiveFedora.config.credentials.length
36
- else
37
- 0
38
- end
39
- end
40
-
41
- ### if you are doing sharding, override this method to do something other than use a sequence
42
- # @return [String] the unique pid for a new object
43
- def assign_pid(obj)
44
- args = {}
45
- args[:namespace] = obj.namespace if obj.namespace
46
- # TODO: This juggling of Fedora credentials & establishing connections should be handled by
47
- # an establish_fedora_connection method,possibly wrap it all into a fedora_connection method - MZ 06-05-2012
48
- if ActiveFedora.config.sharded?
49
- credentials = ActiveFedora.config.credentials[0]
50
- else
51
- credentials = ActiveFedora.config.credentials
52
- end
53
- fedora_connection[0] ||= ActiveFedora::RubydoraConnection.new(credentials)
54
- fedora_connection[0].connection.mint(args)
55
- end
56
- end
57
- end
58
- end
@@ -1,68 +0,0 @@
1
- module ActiveFedora
2
- class SolrDigitalObject
3
- include DigitalObject::DatastreamBootstrap
4
-
5
- attr_reader :pid, :label, :state, :ownerId, :profile, :datastreams, :solr_doc
6
- attr_accessor :original_class
7
-
8
- def initialize(solr_doc, profile_hash, klass=ActiveFedora::Base)
9
- @solr_doc = solr_doc
10
- @pid = solr_doc[SOLR_DOCUMENT_ID]
11
- @profile = {}
12
- profile_hash.each_pair { |key,value| @profile[key] = value.to_s if key =~ /^obj/ }
13
- @profile['objCreateDate'] ||= Time.now.xmlschema
14
- @profile['objLastModDate'] ||= @profile['objCreateDate']
15
-
16
- @datastreams = {}
17
-
18
- dsids = profile_hash['datastreams'].keys
19
- self.original_class = klass
20
- missing = dsids - klass.ds_specs.keys
21
- missing.each do |dsid|
22
- #Initialize the datastreams that are in the solr document, but not found in the classes spec.
23
- mime_type = profile_hash['datastreams'][dsid]['dsMIME']
24
- ds_class = mime_type =~ /[\/\+]xml$/ ? OmDatastream : Datastream
25
- @datastreams[dsid] = ds_class.new(self, dsid)
26
- end
27
-
28
- @label = @profile['objLabel']
29
- @state = @profile['objState']
30
- @ownerId = @profile['objOwnerId']
31
- end
32
-
33
- def freeze
34
- @finished = true
35
- @profile.freeze
36
- @datastreams.freeze
37
- class << self
38
- #Once this instance is frozen create a repository method just for this one instance.
39
- define_method :repository do
40
- ActiveFedora::Base.connection_for_pid(self.pid)
41
- end
42
- end
43
- self
44
- end
45
-
46
- def fetch(field, default=[])
47
- attribute = original_class.defined_attributes[field]
48
- field_name = attribute.primary_solr_name
49
- raise KeyError, "Tried to fetch `#{field}' from solr, but it isn't indexed." unless field_name
50
- val = Array(solr_doc.fetch(field_name, default))
51
- case attribute.type
52
- when :date
53
- val.map{|v| Date.parse v}
54
- else
55
- val
56
- end
57
- end
58
-
59
- def new_record?
60
- false
61
- end
62
-
63
- def uri
64
- "solr:#{pid}"
65
- end
66
-
67
- end
68
- end