active-fedora 3.2.2 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. data/Gemfile +2 -2
  2. data/Gemfile.lock +33 -57
  3. data/History.txt +9 -0
  4. data/active-fedora.gemspec +5 -5
  5. data/lib/active_fedora.rb +37 -10
  6. data/lib/active_fedora/base.rb +0 -18
  7. data/lib/active_fedora/datastream.rb +10 -5
  8. data/lib/active_fedora/datastreams.rb +33 -7
  9. data/lib/active_fedora/dcrdf_datastream.rb +11 -0
  10. data/lib/active_fedora/delegating.rb +2 -2
  11. data/lib/active_fedora/metadata_datastream.rb +3 -2
  12. data/lib/active_fedora/nested_attributes.rb +0 -1
  13. data/lib/active_fedora/ntriples_rdf_datastream.rb +19 -0
  14. data/lib/active_fedora/predicates.rb +4 -0
  15. data/lib/active_fedora/rdf_datastream.rb +108 -0
  16. data/lib/active_fedora/rdf_xml_writer.rb +53 -41
  17. data/lib/active_fedora/relationship_graph.rb +15 -71
  18. data/lib/active_fedora/rels_ext_datastream.rb +1 -4
  19. data/lib/active_fedora/rubydora_connection.rb +2 -9
  20. data/lib/active_fedora/unsaved_digital_object.rb +1 -0
  21. data/lib/active_fedora/version.rb +1 -1
  22. data/lib/tasks/active_fedora_dev.rake +1 -1
  23. data/spec/fixtures/dublin_core_rdf_descMetadata.nt +13 -0
  24. data/spec/fixtures/rails_root/config/fedora.yml +1 -15
  25. data/spec/integration/base_loader_spec.rb +0 -1
  26. data/spec/integration/dc_rdf_datastream_spec.rb +24 -0
  27. data/spec/integration/full_featured_model_spec.rb +1 -1
  28. data/spec/integration/model_spec.rb +0 -1
  29. data/spec/unit/active_fedora_spec.rb +22 -14
  30. data/spec/unit/base_spec.rb +9 -184
  31. data/spec/unit/datastream_collections_spec.rb +2 -2
  32. data/spec/unit/datastream_spec.rb +36 -6
  33. data/spec/unit/datastreams_spec.rb +251 -0
  34. data/spec/unit/dc_rdf_datastream_spec.rb +50 -0
  35. data/spec/unit/metadata_datastream_spec.rb +1 -1
  36. data/spec/unit/nokogiri_datastream_spec.rb +2 -2
  37. data/spec/unit/{rdf_xml_writer.rb → rdf_xml_writer_spec.rb} +8 -8
  38. data/spec/unit/relationship_graph_spec.rb +14 -0
  39. data/spec/unit/rels_ext_datastream_spec.rb +29 -2
  40. data/spec/unit/rubydora_connection_spec.rb +2 -4
  41. data/spec/unit/unsaved_digital_object_spec.rb +22 -9
  42. metadata +106 -258
  43. data/.hg/00changelog.i +0 -0
  44. data/.hg/branch +0 -1
  45. data/.hg/branch.cache +0 -2
  46. data/.hg/dirstate +0 -0
  47. data/.hg/hgrc +0 -2
  48. data/.hg/requires +0 -2
  49. data/.hg/store/00changelog.i +0 -0
  50. data/.hg/store/00manifest.i +0 -0
  51. data/.hg/store/data/.hgignore.i +0 -0
  52. data/.hg/store/data/.hgtags.i +0 -0
  53. data/.hg/store/data/_c_o_p_y_i_n_g.txt.i +0 -0
  54. data/.hg/store/data/_c_o_y_i_n_g._l_e_s_s_e_r.txt.i +0 -0
  55. data/.hg/store/data/_history.txt.i +0 -0
  56. data/.hg/store/data/_license.txt.i +0 -0
  57. data/.hg/store/data/_manifest.txt.i +0 -0
  58. data/.hg/store/data/_post_install.txt.i +0 -0
  59. data/.hg/store/data/_r_e_a_d_m_e.rdoc.i +0 -0
  60. data/.hg/store/data/_r_e_a_d_m_e.txt.i +0 -0
  61. data/.hg/store/data/_rakefile.i +0 -0
  62. data/.hg/store/data/_v_e_r_s_i_o_n.i +0 -0
  63. data/.hg/store/data/active-fedora.gemspec.i +0 -0
  64. data/.hg/store/data/active__fedora/_history.txt.i +0 -0
  65. data/.hg/store/data/active__fedora/_manifest.txt.i +0 -0
  66. data/.hg/store/data/active__fedora/_post_install.txt.i +0 -0
  67. data/.hg/store/data/active__fedora/_r_e_a_d_m_e.rdoc.i +0 -0
  68. data/.hg/store/data/active__fedora/_rakefile.i +0 -0
  69. data/.hg/store/data/active__fedora/lib/active__fedora.rb.i +0 -0
  70. data/.hg/store/data/active__fedora/script/console.i +0 -0
  71. data/.hg/store/data/active__fedora/script/destroy.i +0 -0
  72. data/.hg/store/data/active__fedora/script/generate.i +0 -0
  73. data/.hg/store/data/active__fedora/spec/active__fedora__spec.rb.i +0 -0
  74. data/.hg/store/data/active__fedora/spec/spec__helper.rb.i +0 -0
  75. data/.hg/store/data/config/fedora.yml.i +0 -0
  76. data/.hg/store/data/config/solr__mappings.yml.i +0 -0
  77. data/.hg/store/data/config/solr__mappings__af__0.1.yml.i +0 -0
  78. data/.hg/store/data/config/solr__mappings__bl__2.4.yml.i +0 -0
  79. data/.hg/store/data/lib/active-fedora.rb.i +0 -0
  80. data/.hg/store/data/lib/active__fedora.rb.i +0 -0
  81. data/.hg/store/data/lib/active__fedora/base.rb.i +0 -0
  82. data/.hg/store/data/lib/active__fedora/content__model.rb.i +0 -0
  83. data/.hg/store/data/lib/active__fedora/datastream.rb.i +0 -0
  84. data/.hg/store/data/lib/active__fedora/fedora__object.rb.i +0 -0
  85. data/.hg/store/data/lib/active__fedora/metadata__datastream.rb.i +0 -0
  86. data/.hg/store/data/lib/active__fedora/model.rb.i +0 -0
  87. data/.hg/store/data/lib/active__fedora/property.rb.i +0 -0
  88. data/.hg/store/data/lib/active__fedora/qualified__dublin__core__datastream.rb.i +0 -0
  89. data/.hg/store/data/lib/active__fedora/relationship.rb.i +0 -0
  90. data/.hg/store/data/lib/active__fedora/rels__ext__datastream.rb.i +0 -0
  91. data/.hg/store/data/lib/active__fedora/semantic__node.rb.i +0 -0
  92. data/.hg/store/data/lib/active__fedora/solr__mapper.rb.i +0 -0
  93. data/.hg/store/data/lib/active__fedora/solr__service.rb.i +0 -0
  94. data/.hg/store/data/lib/fedora/base.rb.i +0 -0
  95. data/.hg/store/data/lib/fedora/connection.rb.i +0 -0
  96. data/.hg/store/data/lib/fedora/datastream.rb.i +0 -0
  97. data/.hg/store/data/lib/fedora/fedora__object.rb.i +0 -0
  98. data/.hg/store/data/lib/fedora/formats.rb.i +0 -0
  99. data/.hg/store/data/lib/fedora/generic__search.rb.i +0 -0
  100. data/.hg/store/data/lib/fedora/repository.rb.i +0 -0
  101. data/.hg/store/data/lib/ruby-fedora.rb.i +0 -0
  102. data/.hg/store/data/lib/util/class__level__inheritable__attributes.rb.i +0 -0
  103. data/.hg/store/data/script/console.i +0 -0
  104. data/.hg/store/data/script/destroy.i +0 -0
  105. data/.hg/store/data/script/generate.i +0 -0
  106. data/.hg/store/data/solr/config/schema-1.5.xml.i +0 -0
  107. data/.hg/store/data/solr/config/schema.xml.i +0 -0
  108. data/.hg/store/data/solr/config/solrconfig-1.5.xml.i +0 -0
  109. data/.hg/store/data/spec/fixtures/changeme155.xml.i +0 -0
  110. data/.hg/store/data/spec/fixtures/dino.jpg.i +0 -0
  111. data/.hg/store/data/spec/fixtures/minivan.jpg.d +0 -0
  112. data/.hg/store/data/spec/fixtures/minivan.jpg.i +0 -0
  113. data/.hg/store/data/spec/fixtures/test__12.foxml.xml.i +0 -0
  114. data/.hg/store/data/spec/integration/active__fedora/base__spec.rb.i +0 -0
  115. data/.hg/store/data/spec/integration/active__fedora/datastream__spec.rb.i +0 -0
  116. data/.hg/store/data/spec/integration/active__fedora/fedora__object__spec.rb.i +0 -0
  117. data/.hg/store/data/spec/integration/active__fedora/full__featured__model__spec.rb.i +0 -0
  118. data/.hg/store/data/spec/integration/active__fedora/model__spec.rb.i +0 -0
  119. data/.hg/store/data/spec/integration/active__fedora/rels__ext__datastream__spec.rb.i +0 -0
  120. data/.hg/store/data/spec/integration/active__fedora/semantic__node__spec.rb.i +0 -0
  121. data/.hg/store/data/spec/integration/base__file__management__spec.rb.i +0 -0
  122. data/.hg/store/data/spec/integration/base__spec.rb.i +0 -0
  123. data/.hg/store/data/spec/integration/bug__spec.rb.i +0 -0
  124. data/.hg/store/data/spec/integration/datastream__spec.rb.i +0 -0
  125. data/.hg/store/data/spec/integration/datastreams__crud__spec.rb.i +0 -0
  126. data/.hg/store/data/spec/integration/fedora__object__spec.rb.i +0 -0
  127. data/.hg/store/data/spec/integration/full__featured__model__spec.rb.i +0 -0
  128. data/.hg/store/data/spec/integration/model__spec.rb.i +0 -0
  129. data/.hg/store/data/spec/integration/rels__ext__datastream__spec.rb.i +0 -0
  130. data/.hg/store/data/spec/integration/repository__spec.rb.i +0 -0
  131. data/.hg/store/data/spec/integration/rf__fedora__object__spec.rb.i +0 -0
  132. data/.hg/store/data/spec/integration/semantic__node__spec.rb.i +0 -0
  133. data/.hg/store/data/spec/integration/solr__service__spec.rb.i +0 -0
  134. data/.hg/store/data/spec/samples/models/audio__record.rb.i +0 -0
  135. data/.hg/store/data/spec/samples/models/image.rb.i +0 -0
  136. data/.hg/store/data/spec/samples/models/oral__history.rb.i +0 -0
  137. data/.hg/store/data/spec/samples/models/seminar.rb.i +0 -0
  138. data/.hg/store/data/spec/samples/models/seminar__audio__file.rb.i +0 -0
  139. data/.hg/store/data/spec/samples/oh__qdc.xml.i +0 -0
  140. data/.hg/store/data/spec/samples/oral__history.rb.i +0 -0
  141. data/.hg/store/data/spec/samples/oral__history__sample.xml.i +0 -0
  142. data/.hg/store/data/spec/samples/oral__history__sample__model.rb.i +0 -0
  143. data/.hg/store/data/spec/samples/oral__history__xml.xml.i +0 -0
  144. data/.hg/store/data/spec/spec.opts.i +0 -0
  145. data/.hg/store/data/spec/spec__helper.rb.i +0 -0
  146. data/.hg/store/data/spec/unit/active__fedora/base__cma__spec.rb.i +0 -0
  147. data/.hg/store/data/spec/unit/active__fedora/base__extra__spec.rb.i +0 -0
  148. data/.hg/store/data/spec/unit/active__fedora/base__spec.rb.i +0 -0
  149. data/.hg/store/data/spec/unit/active__fedora/content__model__spec.rb.i +0 -0
  150. data/.hg/store/data/spec/unit/active__fedora/datastream__spec.rb.i +0 -0
  151. data/.hg/store/data/spec/unit/active__fedora/inheritance__spec.rb.i +0 -0
  152. data/.hg/store/data/spec/unit/active__fedora/metadata__datastream__spec.rb.i +0 -0
  153. data/.hg/store/data/spec/unit/active__fedora/model__spec.rb.i +0 -0
  154. data/.hg/store/data/spec/unit/active__fedora/property__spec.rb.i +0 -0
  155. data/.hg/store/data/spec/unit/active__fedora/qualified__dublin__core__datastream__spec.rb.i +0 -0
  156. data/.hg/store/data/spec/unit/active__fedora/relationship__spec.rb.i +0 -0
  157. data/.hg/store/data/spec/unit/active__fedora/rels__ext__datastream__spec.rb.i +0 -0
  158. data/.hg/store/data/spec/unit/active__fedora/semantic__node__spec.rb.i +0 -0
  159. data/.hg/store/data/spec/unit/active__fedora/solr__service__spec.rb.i +0 -0
  160. data/.hg/store/data/spec/unit/active__fedora__spec.rb.i +0 -0
  161. data/.hg/store/data/spec/unit/base__cma__spec.rb.i +0 -0
  162. data/.hg/store/data/spec/unit/base__datastream__management__spec.rb.i +0 -0
  163. data/.hg/store/data/spec/unit/base__extra__spec.rb.i +0 -0
  164. data/.hg/store/data/spec/unit/base__file__management__spec.rb.i +0 -0
  165. data/.hg/store/data/spec/unit/base__loader__spec.rb.i +0 -0
  166. data/.hg/store/data/spec/unit/base__spec.rb.i +0 -0
  167. data/.hg/store/data/spec/unit/connection__spec.rb.i +0 -0
  168. data/.hg/store/data/spec/unit/content__model__spec.rb.i +0 -0
  169. data/.hg/store/data/spec/unit/datastream__concurrency__spec.rb.i +0 -0
  170. data/.hg/store/data/spec/unit/datastream__spec.rb.i +0 -0
  171. data/.hg/store/data/spec/unit/fedora__object__spec.rb.i +0 -0
  172. data/.hg/store/data/spec/unit/inheritance__spec.rb.i +0 -0
  173. data/.hg/store/data/spec/unit/metadata__datastream__spec.rb.i +0 -0
  174. data/.hg/store/data/spec/unit/model__spec.rb.i +0 -0
  175. data/.hg/store/data/spec/unit/property__spec.rb.i +0 -0
  176. data/.hg/store/data/spec/unit/qualified__dublin__core__datastream__spec.rb.i +0 -0
  177. data/.hg/store/data/spec/unit/relationship__spec.rb.i +0 -0
  178. data/.hg/store/data/spec/unit/rels__ext__datastream__spec.rb.i +0 -0
  179. data/.hg/store/data/spec/unit/repository__spec.rb.i +0 -0
  180. data/.hg/store/data/spec/unit/rf__datastream__spec.rb.i +0 -0
  181. data/.hg/store/data/spec/unit/semantic__node__spec.rb.i +0 -0
  182. data/.hg/store/data/spec/unit/solr__config__options__spec.rb.i +0 -0
  183. data/.hg/store/data/spec/unit/solr__mapper__spec.rb.i +0 -0
  184. data/.hg/store/data/spec/unit/solr__service__spec.rb.i +0 -0
  185. data/.hg/store/data/tasks/rspec.rake.i +0 -0
  186. data/.hg/store/undo +0 -0
  187. data/.hg/undo.branch +0 -1
  188. data/.hg/undo.dirstate +0 -0
  189. data/.hgignore +0 -7
  190. data/.hgtags +0 -14
@@ -0,0 +1,11 @@
1
+ module ActiveFedora
2
+ class DCRDFDatastream < NtriplesRDFDatastream
3
+
4
+ # given a symbol, resolve the predicate as a RDF::URI
5
+ # if the predicate is not in DC, return nil
6
+ def resolve_predicate(name)
7
+ RDF::DC.send(name) if RDF::DC.respond_to? name
8
+ end
9
+
10
+ end
11
+ end
@@ -31,7 +31,7 @@ module ActiveFedora
31
31
  def create_delegate_accessor(field, args)
32
32
  define_method field do
33
33
  ds = self.send(args[:to])
34
- val = if ds.kind_of? ActiveFedora::MetadataDatastream
34
+ val = if ds.kind_of?(ActiveFedora::MetadataDatastream) || ds.kind_of?(ActiveFedora::DCRDFDatastream)
35
35
  ds.send(:get_values, field)
36
36
  else
37
37
  terminology = args[:at] || [field]
@@ -45,7 +45,7 @@ module ActiveFedora
45
45
  def create_delegate_setter(field, args)
46
46
  define_method "#{field}=".to_sym do |v|
47
47
  ds = self.send(args[:to])
48
- if ds.kind_of? ActiveFedora::MetadataDatastream
48
+ if ds.kind_of?(ActiveFedora::MetadataDatastream) || ds.kind_of?(ActiveFedora::DCRDFDatastream)
49
49
  ds.send(:set_value, field, v)
50
50
  else
51
51
  terminology = args[:at] || [field]
@@ -129,7 +129,8 @@ module ActiveFedora
129
129
  end
130
130
  end
131
131
 
132
- new_values.each do |y,z|
132
+ new_values.keys.sort { |a,b| a.to_i <=> b.to_i }.each do |y|
133
+ z = new_values[y]
133
134
  result[field_name].delete(y)
134
135
  current_values<<z #just append everything left
135
136
  new_array_index = current_values.length - 1
@@ -199,7 +200,7 @@ module ActiveFedora
199
200
  end
200
201
 
201
202
  builder = Nokogiri::XML::Builder.with(xml_insertion_point) do |xml|
202
- fields.each_pair do |field,field_info|
203
+ fields.each do |field,field_info|
203
204
  element_attrs = field_info[:element_attrs].nil? ? {} : field_info[:element_attrs]
204
205
  values = field_info[:values]
205
206
  values = [values] unless values.respond_to? :each
@@ -1,7 +1,6 @@
1
1
  require 'active_support/core_ext/hash/except'
2
2
  require 'active_support/core_ext/object/try'
3
3
  require 'active_support/core_ext/object/blank'
4
- require 'active_support/core_ext/hash/indifferent_access'
5
4
 
6
5
 
7
6
  module ActiveFedora
@@ -0,0 +1,19 @@
1
+ require 'rdf/ntriples'
2
+
3
+ module ActiveFedora
4
+ class NtriplesRDFDatastream < RDFDatastream
5
+
6
+ def serialization_format
7
+ :ntriples
8
+ end
9
+
10
+ def mimeType
11
+ 'text/plain'
12
+ end
13
+
14
+ def controlGroup
15
+ 'M'
16
+ end
17
+ end
18
+ end
19
+
@@ -54,6 +54,10 @@ module ActiveFedora
54
54
  @@predicate_config ||= YAML::load(File.open(ActiveFedora.predicate_config)) if File.exist?(ActiveFedora.predicate_config)
55
55
  end
56
56
 
57
+ def self.predicate_namespaces
58
+ predicate_config[:predicate_namespaces] || {}
59
+ end
60
+
57
61
  def self.predicate_mappings
58
62
  predicate_config[:predicate_mapping]
59
63
  end
@@ -0,0 +1,108 @@
1
+ require 'rdf'
2
+
3
+ module ActiveFedora
4
+ class RDFDatastream < Datastream
5
+ attr_accessor :loaded
6
+
7
+ def ensure_loaded
8
+ return if loaded
9
+ self.loaded = true
10
+ unless new?
11
+ deserialize content
12
+ end
13
+ end
14
+
15
+ def serialize! # :nodoc:
16
+ if graph.dirty
17
+ return unless loaded
18
+ self.content = serialize
19
+ end
20
+ end
21
+
22
+ def graph
23
+ @graph ||= RelationshipGraph.new
24
+ end
25
+
26
+ def get_values(predicate)
27
+ ensure_loaded
28
+ predicate = resolve_predicate(predicate) unless predicate.kind_of? RDF::URI
29
+ results = graph[predicate]
30
+ res = []
31
+ results.each do |object|
32
+ res << (object.kind_of?(RDF::Literal) ? object.value : object.to_str)
33
+ end
34
+ res
35
+ end
36
+
37
+ # if there are any existing statements with this predicate, replace them
38
+ def set_value(predicate, args)
39
+ ensure_loaded
40
+ predicate = resolve_predicate(predicate) unless predicate.kind_of? RDF::URI
41
+ graph.delete(predicate)
42
+ graph.add(predicate, args, true)
43
+ end
44
+
45
+ # append a value
46
+ def append(predicate, args)
47
+ ensure_loaded
48
+ graph.add(predicate, args, true)
49
+ end
50
+
51
+
52
+
53
+ def method_missing(name, *args)
54
+ if pred = resolve_predicate(name)
55
+ get_values(pred)
56
+ elsif (md = /^([^=]+)=$/.match(name.to_s)) && pred = resolve_predicate(md[1])
57
+ set_value(pred, *args)
58
+ else
59
+ super
60
+ end
61
+ end
62
+
63
+ def serialization_format
64
+ raise "you must override the `serialization_format' method in a subclass"
65
+ end
66
+
67
+
68
+ # given a symbol or string, map it to a RDF::URI
69
+ # if the provided parameter is not allowed in the vocabulary, return nil
70
+ def resolve_predicate(predicate)
71
+ raise "you must override the `resolve_predicate' method in a subclass"
72
+ end
73
+
74
+ # Populate a RDFDatastream object based on the "datastream" content
75
+ # Assumes that the datastream contains RDF XML from a Fedora RELS-EXT datastream
76
+ # @param [ActiveFedora::MetadataDatastream] tmpl the Datastream object that you are populating
77
+ # @param [String] the "rdf" node
78
+ def deserialize(data)
79
+ unless data.nil?
80
+ RDF::Reader.for(serialization_format).new(data) do |reader|
81
+ reader.each_statement do |statement|
82
+ literal = statement.object.kind_of?(RDF::Literal)
83
+ object = literal ? statement.object.value : statement.object.to_str
84
+ graph.add(statement.predicate, object, literal)
85
+ end
86
+ end
87
+ end
88
+ graph
89
+ end
90
+
91
+ # Creates a RDF datastream for insertion into a Fedora Object
92
+ # @param [String] pid
93
+ # @param [Hash] relationships (optional) @default self.relationships
94
+ # Note: This method is implemented on SemanticNode instead of RelsExtDatastream because SemanticNode contains the relationships array
95
+ def serialize()
96
+ out = RDF::Writer.for(serialization_format).buffer do |writer|
97
+ graph.to_graph("info:fedora/#{pid}").each_statement do |statement|
98
+ writer << statement
99
+ end
100
+ end
101
+ out
102
+ end
103
+
104
+
105
+ end
106
+
107
+ end
108
+
@@ -9,61 +9,73 @@ module ActiveFedora
9
9
  # an rdf:type assertion is present; this is incompatible with Fedora
10
10
  class RDFXMLWriter < RDF::RDFXML::Writer
11
11
  def subject(subject, parent_node)
12
- node = nil
13
12
 
14
13
  raise RDF::WriterError, "Illegal use of subject #{subject.inspect}, not supported in RDF/XML" unless subject.resource?
15
14
 
16
- if !is_done?(subject)
17
- subject_done(subject)
18
- properties = @graph.properties(subject)
19
- add_debug {"subject: #{subject.inspect}, props: #{properties.inspect}"}
15
+ node = if !is_done?(subject)
16
+ subject_not_done(subject, parent_node)
17
+ elsif @force_RDF_about.include?(subject)
18
+ force_about(subject, parent_node)
19
+ end
20
+ @force_RDF_about.delete(subject)
20
21
 
21
- @graph.query(:subject => subject).each do |st|
22
- raise RDF::WriterError, "Illegal use of predicate #{st.predicate.inspect}, not supported in RDF/XML" unless st.predicate.uri?
23
- end
22
+ parent_node.add_child(node) if node
23
+ end
24
24
 
25
- prop_list = order_properties(properties)
26
- add_debug {"=> property order: #{prop_list.to_sentence}"}
25
+ private
27
26
 
28
- qname = "rdf:Description"
29
- prefixes[:rdf] = RDF.to_uri
27
+ def force_about(subject, parent_node)
28
+ add_debug {"subject: #{subject.inspect}, force about"}
29
+ node = Nokogiri::XML::Element.new("rdf:Description", parent_node.document)
30
+ if subject.is_a?(RDF::Node)
31
+ node["rdf:nodeID"] = subject.id
32
+ else
33
+ node["rdf:about"] = relativize(subject)
34
+ end
35
+ node
36
+ end
30
37
 
31
- node = Nokogiri::XML::Element.new(qname, parent_node.document)
32
-
33
- if subject.is_a?(RDF::Node)
34
- # Only need nodeID if it's referenced elsewhere
35
- if ref_count(subject) > (@depth == 0 ? 0 : 1)
36
- node["rdf:nodeID"] = subject.id
37
- else
38
- node.add_child(Nokogiri::XML::Comment.new(node.document, "Serialization for #{subject}")) if RDF::RDFXML::debug?
39
- end
40
- else
41
- node["rdf:about"] = relativize(subject)
42
- end
38
+ def subject_not_done(subject, parent_node)
39
+ subject_done(subject)
40
+ properties = @graph.properties(subject)
41
+ add_debug {"subject: #{subject.inspect}, props: #{properties.inspect}"}
42
+
43
+ @graph.query(:subject => subject).each do |st|
44
+ raise RDF::WriterError, "Illegal use of predicate #{st.predicate.inspect}, not supported in RDF/XML" unless st.predicate.uri?
45
+ end
43
46
 
44
- prop_list.each do |prop|
45
- prop_ref = RDF::URI.intern(prop)
46
-
47
- properties[prop].each do |object|
48
- raise RDF::WriterError, "Illegal use of object #{object.inspect}, not supported in RDF/XML" unless object.resource? || object.literal?
47
+ prop_list = order_properties(properties)
48
+ add_debug {"=> property order: #{prop_list.to_sentence}"}
49
49
 
50
- @depth += 1
51
- predicate(prop_ref, object, node, properties[prop].length == 1)
52
- @depth -= 1
53
- end
54
- end
55
- elsif @force_RDF_about.include?(subject)
56
- add_debug {"subject: #{subject.inspect}, force about"}
57
- node = Nokogiri::XML::Element.new("rdf:Description", parent_node.document)
58
- if subject.is_a?(RDF::Node)
50
+ qname = "rdf:Description"
51
+ prefixes[:rdf] = RDF.to_uri
52
+
53
+ node = Nokogiri::XML::Element.new(qname, parent_node.document)
54
+
55
+ if subject.is_a?(RDF::Node)
56
+ # Only need nodeID if it's referenced elsewhere
57
+ if ref_count(subject) > (@depth == 0 ? 0 : 1)
59
58
  node["rdf:nodeID"] = subject.id
60
59
  else
61
- node["rdf:about"] = relativize(subject)
60
+ node.add_child(Nokogiri::XML::Comment.new(node.document, "Serialization for #{subject}")) if RDF::RDFXML::debug?
62
61
  end
62
+ else
63
+ node["rdf:about"] = relativize(subject)
63
64
  end
64
- @force_RDF_about.delete(subject)
65
65
 
66
- parent_node.add_child(node) if node
66
+ prop_list.each do |prop|
67
+ prop_ref = RDF::URI.intern(prop)
68
+
69
+ properties[prop].each do |object|
70
+ raise RDF::WriterError, "Illegal use of object #{object.inspect}, not supported in RDF/XML" unless object.resource? || object.literal?
71
+
72
+ @depth += 1
73
+ predicate(prop_ref, object, node, properties[prop].length == 1)
74
+ @depth -= 1
75
+ end
76
+ end
77
+ node
67
78
  end
79
+
68
80
  end
69
81
  end
@@ -8,6 +8,10 @@ module ActiveFedora
8
8
  self.dirty = false
9
9
  self.relationships = {}
10
10
  end
11
+
12
+ def has_predicate?(predicate)
13
+ relationships.has_key? predicate
14
+ end
11
15
 
12
16
  def add(predicate, object, literal=false)
13
17
  unless relationships.has_key? predicate
@@ -20,8 +24,16 @@ module ActiveFedora
20
24
  end
21
25
  end
22
26
 
23
- def delete(predicate, object)
27
+ # Remove the statement matching the predicate and object
28
+ # [predicate] the predicate to delete
29
+ # [object] the object to delete, if nil, all statements with this predicate are deleted.
30
+ def delete(predicate, object = nil)
24
31
  return unless relationships.has_key? predicate
32
+ if object.nil?
33
+ @dirty = true
34
+ relationships.delete(predicate)
35
+ return
36
+ end
25
37
  if relationships[predicate].include?(object)
26
38
  @dirty = true
27
39
  relationships[predicate].delete(object)
@@ -32,7 +44,6 @@ module ActiveFedora
32
44
  elsif object.is_a? String
33
45
  relationships[predicate].delete_if{|obj| obj.respond_to?(:internal_uri) && obj.internal_uri == object}
34
46
  end
35
-
36
47
  end
37
48
 
38
49
  def [](predicate)
@@ -76,77 +87,10 @@ module ActiveFedora
76
87
  end
77
88
  object = RDF::URI.new(target)
78
89
  end
79
- RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(predicate), object)
90
+ predicate = ActiveFedora::Predicates.find_graph_predicate(predicate) unless predicate.kind_of? RDF::URI
91
+ RDF::Statement.new(subject, predicate, object)
80
92
 
81
93
  end
82
94
 
83
- # def find_graph_predicate(predicate)
84
- # #TODO, these could be cached
85
- # case predicate
86
- # when :has_model, "hasModel", :hasModel
87
- # xmlns="info:fedora/fedora-system:def/model#"
88
- # begin
89
- # rel_predicate = ActiveFedora::Predicates.predicate_lookup(predicate,xmlns)
90
- # rescue UnregisteredPredicateError
91
- # xmlns = nil
92
- # rel_predicate = nil
93
- # end
94
- # else
95
- # xmlns="info:fedora/fedora-system:def/relations-external#"
96
- # begin
97
- # rel_predicate = ActiveFedora::Predicates.predicate_lookup(predicate,xmlns)
98
- # rescue UnregisteredPredicateError
99
- # xmlns = nil
100
- # rel_predicate = nil
101
- # end
102
- # end
103
- #
104
- # unless xmlns && rel_predicate
105
- # rel_predicate, xmlns = ActiveFedora::Predicates.find_predicate(predicate)
106
- # end
107
- # self.class.vocabularies[xmlns][rel_predicate]
108
- # end
109
- # def self.vocabularies
110
- # return @vocabularies if @vocabularies
111
- # @vocabularies = {}
112
- # predicate_mappings.keys.each { |ns| @vocabularies[ns] = RDF::Vocabulary.new(ns)}
113
- # @vocabularies
114
- # end
115
-
116
- # # If predicate is a symbol, looks up the predicate in the predicate_mappings
117
- # # If predicate is not a Symbol, returns the predicate untouched
118
- # # @raise UnregisteredPredicateError if the predicate is a symbol but is not found in the predicate_mappings
119
- # def self.predicate_lookup(predicate,namespace="info:fedora/fedora-system:def/relations-external#")
120
- # if predicate.class == Symbol
121
- # if predicate_mappings[namespace].has_key?(predicate)
122
- # return predicate_mappings[namespace][predicate]
123
- # else
124
- # raise ActiveFedora::UnregisteredPredicateError
125
- # end
126
- # end
127
- # return predicate
128
- # end
129
-
130
- # def self.predicate_config
131
- # @@predicate_config ||= YAML::load(File.open(ActiveFedora.predicate_config)) if File.exist?(ActiveFedora.predicate_config)
132
- # end
133
-
134
- # def self.predicate_mappings
135
- # predicate_config[:predicate_mapping]
136
- # end
137
-
138
- # def self.default_predicate_namespace
139
- # predicate_config[:default_namespace]
140
- # end
141
-
142
- # def self.find_predicate(predicate)
143
- # predicate_mappings.each do |namespace,predicates|
144
- # if predicates.fetch(predicate,nil)
145
- # return predicates[predicate], namespace
146
- # end
147
- # end
148
- # raise ActiveFedora::UnregisteredPredicateError, "Unregistered predicate: #{predicate.inspect}"
149
- # end
150
-
151
95
  end
152
96
  end
@@ -46,17 +46,14 @@ module ActiveFedora
46
46
  end
47
47
 
48
48
  # Creates a RELS-EXT datastream for insertion into a Fedora Object
49
- # @param [String] pid
50
- # @param [Hash] relationships (optional) @default self.relationships
51
- # Note: This method is implemented on SemanticNode instead of RelsExtDatastream because SemanticNode contains the relationships array
52
49
  def to_rels_ext()
53
50
  xml = ActiveFedora::RDFXMLWriter.buffer do |writer|
51
+ writer.prefixes.merge! ActiveFedora::Predicates.predicate_namespaces
54
52
  model.relationships.each_statement do |statement|
55
53
  writer << statement
56
54
  end
57
55
  end
58
56
  xml
59
-
60
57
  end
61
58
 
62
59
  def self.short_predicate(predicate)