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.
- data/Gemfile +2 -2
- data/Gemfile.lock +33 -57
- data/History.txt +9 -0
- data/active-fedora.gemspec +5 -5
- data/lib/active_fedora.rb +37 -10
- data/lib/active_fedora/base.rb +0 -18
- data/lib/active_fedora/datastream.rb +10 -5
- data/lib/active_fedora/datastreams.rb +33 -7
- data/lib/active_fedora/dcrdf_datastream.rb +11 -0
- data/lib/active_fedora/delegating.rb +2 -2
- data/lib/active_fedora/metadata_datastream.rb +3 -2
- data/lib/active_fedora/nested_attributes.rb +0 -1
- data/lib/active_fedora/ntriples_rdf_datastream.rb +19 -0
- data/lib/active_fedora/predicates.rb +4 -0
- data/lib/active_fedora/rdf_datastream.rb +108 -0
- data/lib/active_fedora/rdf_xml_writer.rb +53 -41
- data/lib/active_fedora/relationship_graph.rb +15 -71
- data/lib/active_fedora/rels_ext_datastream.rb +1 -4
- data/lib/active_fedora/rubydora_connection.rb +2 -9
- data/lib/active_fedora/unsaved_digital_object.rb +1 -0
- data/lib/active_fedora/version.rb +1 -1
- data/lib/tasks/active_fedora_dev.rake +1 -1
- data/spec/fixtures/dublin_core_rdf_descMetadata.nt +13 -0
- data/spec/fixtures/rails_root/config/fedora.yml +1 -15
- data/spec/integration/base_loader_spec.rb +0 -1
- data/spec/integration/dc_rdf_datastream_spec.rb +24 -0
- data/spec/integration/full_featured_model_spec.rb +1 -1
- data/spec/integration/model_spec.rb +0 -1
- data/spec/unit/active_fedora_spec.rb +22 -14
- data/spec/unit/base_spec.rb +9 -184
- data/spec/unit/datastream_collections_spec.rb +2 -2
- data/spec/unit/datastream_spec.rb +36 -6
- data/spec/unit/datastreams_spec.rb +251 -0
- data/spec/unit/dc_rdf_datastream_spec.rb +50 -0
- data/spec/unit/metadata_datastream_spec.rb +1 -1
- data/spec/unit/nokogiri_datastream_spec.rb +2 -2
- data/spec/unit/{rdf_xml_writer.rb → rdf_xml_writer_spec.rb} +8 -8
- data/spec/unit/relationship_graph_spec.rb +14 -0
- data/spec/unit/rels_ext_datastream_spec.rb +29 -2
- data/spec/unit/rubydora_connection_spec.rb +2 -4
- data/spec/unit/unsaved_digital_object_spec.rb +22 -9
- metadata +106 -258
- data/.hg/00changelog.i +0 -0
- data/.hg/branch +0 -1
- data/.hg/branch.cache +0 -2
- data/.hg/dirstate +0 -0
- data/.hg/hgrc +0 -2
- data/.hg/requires +0 -2
- data/.hg/store/00changelog.i +0 -0
- data/.hg/store/00manifest.i +0 -0
- data/.hg/store/data/.hgignore.i +0 -0
- data/.hg/store/data/.hgtags.i +0 -0
- data/.hg/store/data/_c_o_p_y_i_n_g.txt.i +0 -0
- data/.hg/store/data/_c_o_y_i_n_g._l_e_s_s_e_r.txt.i +0 -0
- data/.hg/store/data/_history.txt.i +0 -0
- data/.hg/store/data/_license.txt.i +0 -0
- data/.hg/store/data/_manifest.txt.i +0 -0
- data/.hg/store/data/_post_install.txt.i +0 -0
- data/.hg/store/data/_r_e_a_d_m_e.rdoc.i +0 -0
- data/.hg/store/data/_r_e_a_d_m_e.txt.i +0 -0
- data/.hg/store/data/_rakefile.i +0 -0
- data/.hg/store/data/_v_e_r_s_i_o_n.i +0 -0
- data/.hg/store/data/active-fedora.gemspec.i +0 -0
- data/.hg/store/data/active__fedora/_history.txt.i +0 -0
- data/.hg/store/data/active__fedora/_manifest.txt.i +0 -0
- data/.hg/store/data/active__fedora/_post_install.txt.i +0 -0
- data/.hg/store/data/active__fedora/_r_e_a_d_m_e.rdoc.i +0 -0
- data/.hg/store/data/active__fedora/_rakefile.i +0 -0
- data/.hg/store/data/active__fedora/lib/active__fedora.rb.i +0 -0
- data/.hg/store/data/active__fedora/script/console.i +0 -0
- data/.hg/store/data/active__fedora/script/destroy.i +0 -0
- data/.hg/store/data/active__fedora/script/generate.i +0 -0
- data/.hg/store/data/active__fedora/spec/active__fedora__spec.rb.i +0 -0
- data/.hg/store/data/active__fedora/spec/spec__helper.rb.i +0 -0
- data/.hg/store/data/config/fedora.yml.i +0 -0
- data/.hg/store/data/config/solr__mappings.yml.i +0 -0
- data/.hg/store/data/config/solr__mappings__af__0.1.yml.i +0 -0
- data/.hg/store/data/config/solr__mappings__bl__2.4.yml.i +0 -0
- data/.hg/store/data/lib/active-fedora.rb.i +0 -0
- data/.hg/store/data/lib/active__fedora.rb.i +0 -0
- data/.hg/store/data/lib/active__fedora/base.rb.i +0 -0
- data/.hg/store/data/lib/active__fedora/content__model.rb.i +0 -0
- data/.hg/store/data/lib/active__fedora/datastream.rb.i +0 -0
- data/.hg/store/data/lib/active__fedora/fedora__object.rb.i +0 -0
- data/.hg/store/data/lib/active__fedora/metadata__datastream.rb.i +0 -0
- data/.hg/store/data/lib/active__fedora/model.rb.i +0 -0
- data/.hg/store/data/lib/active__fedora/property.rb.i +0 -0
- data/.hg/store/data/lib/active__fedora/qualified__dublin__core__datastream.rb.i +0 -0
- data/.hg/store/data/lib/active__fedora/relationship.rb.i +0 -0
- data/.hg/store/data/lib/active__fedora/rels__ext__datastream.rb.i +0 -0
- data/.hg/store/data/lib/active__fedora/semantic__node.rb.i +0 -0
- data/.hg/store/data/lib/active__fedora/solr__mapper.rb.i +0 -0
- data/.hg/store/data/lib/active__fedora/solr__service.rb.i +0 -0
- data/.hg/store/data/lib/fedora/base.rb.i +0 -0
- data/.hg/store/data/lib/fedora/connection.rb.i +0 -0
- data/.hg/store/data/lib/fedora/datastream.rb.i +0 -0
- data/.hg/store/data/lib/fedora/fedora__object.rb.i +0 -0
- data/.hg/store/data/lib/fedora/formats.rb.i +0 -0
- data/.hg/store/data/lib/fedora/generic__search.rb.i +0 -0
- data/.hg/store/data/lib/fedora/repository.rb.i +0 -0
- data/.hg/store/data/lib/ruby-fedora.rb.i +0 -0
- data/.hg/store/data/lib/util/class__level__inheritable__attributes.rb.i +0 -0
- data/.hg/store/data/script/console.i +0 -0
- data/.hg/store/data/script/destroy.i +0 -0
- data/.hg/store/data/script/generate.i +0 -0
- data/.hg/store/data/solr/config/schema-1.5.xml.i +0 -0
- data/.hg/store/data/solr/config/schema.xml.i +0 -0
- data/.hg/store/data/solr/config/solrconfig-1.5.xml.i +0 -0
- data/.hg/store/data/spec/fixtures/changeme155.xml.i +0 -0
- data/.hg/store/data/spec/fixtures/dino.jpg.i +0 -0
- data/.hg/store/data/spec/fixtures/minivan.jpg.d +0 -0
- data/.hg/store/data/spec/fixtures/minivan.jpg.i +0 -0
- data/.hg/store/data/spec/fixtures/test__12.foxml.xml.i +0 -0
- data/.hg/store/data/spec/integration/active__fedora/base__spec.rb.i +0 -0
- data/.hg/store/data/spec/integration/active__fedora/datastream__spec.rb.i +0 -0
- data/.hg/store/data/spec/integration/active__fedora/fedora__object__spec.rb.i +0 -0
- data/.hg/store/data/spec/integration/active__fedora/full__featured__model__spec.rb.i +0 -0
- data/.hg/store/data/spec/integration/active__fedora/model__spec.rb.i +0 -0
- data/.hg/store/data/spec/integration/active__fedora/rels__ext__datastream__spec.rb.i +0 -0
- data/.hg/store/data/spec/integration/active__fedora/semantic__node__spec.rb.i +0 -0
- data/.hg/store/data/spec/integration/base__file__management__spec.rb.i +0 -0
- data/.hg/store/data/spec/integration/base__spec.rb.i +0 -0
- data/.hg/store/data/spec/integration/bug__spec.rb.i +0 -0
- data/.hg/store/data/spec/integration/datastream__spec.rb.i +0 -0
- data/.hg/store/data/spec/integration/datastreams__crud__spec.rb.i +0 -0
- data/.hg/store/data/spec/integration/fedora__object__spec.rb.i +0 -0
- data/.hg/store/data/spec/integration/full__featured__model__spec.rb.i +0 -0
- data/.hg/store/data/spec/integration/model__spec.rb.i +0 -0
- data/.hg/store/data/spec/integration/rels__ext__datastream__spec.rb.i +0 -0
- data/.hg/store/data/spec/integration/repository__spec.rb.i +0 -0
- data/.hg/store/data/spec/integration/rf__fedora__object__spec.rb.i +0 -0
- data/.hg/store/data/spec/integration/semantic__node__spec.rb.i +0 -0
- data/.hg/store/data/spec/integration/solr__service__spec.rb.i +0 -0
- data/.hg/store/data/spec/samples/models/audio__record.rb.i +0 -0
- data/.hg/store/data/spec/samples/models/image.rb.i +0 -0
- data/.hg/store/data/spec/samples/models/oral__history.rb.i +0 -0
- data/.hg/store/data/spec/samples/models/seminar.rb.i +0 -0
- data/.hg/store/data/spec/samples/models/seminar__audio__file.rb.i +0 -0
- data/.hg/store/data/spec/samples/oh__qdc.xml.i +0 -0
- data/.hg/store/data/spec/samples/oral__history.rb.i +0 -0
- data/.hg/store/data/spec/samples/oral__history__sample.xml.i +0 -0
- data/.hg/store/data/spec/samples/oral__history__sample__model.rb.i +0 -0
- data/.hg/store/data/spec/samples/oral__history__xml.xml.i +0 -0
- data/.hg/store/data/spec/spec.opts.i +0 -0
- data/.hg/store/data/spec/spec__helper.rb.i +0 -0
- data/.hg/store/data/spec/unit/active__fedora/base__cma__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/active__fedora/base__extra__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/active__fedora/base__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/active__fedora/content__model__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/active__fedora/datastream__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/active__fedora/inheritance__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/active__fedora/metadata__datastream__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/active__fedora/model__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/active__fedora/property__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/active__fedora/qualified__dublin__core__datastream__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/active__fedora/relationship__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/active__fedora/rels__ext__datastream__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/active__fedora/semantic__node__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/active__fedora/solr__service__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/active__fedora__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/base__cma__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/base__datastream__management__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/base__extra__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/base__file__management__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/base__loader__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/base__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/connection__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/content__model__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/datastream__concurrency__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/datastream__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/fedora__object__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/inheritance__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/metadata__datastream__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/model__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/property__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/qualified__dublin__core__datastream__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/relationship__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/rels__ext__datastream__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/repository__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/rf__datastream__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/semantic__node__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/solr__config__options__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/solr__mapper__spec.rb.i +0 -0
- data/.hg/store/data/spec/unit/solr__service__spec.rb.i +0 -0
- data/.hg/store/data/tasks/rspec.rake.i +0 -0
- data/.hg/store/undo +0 -0
- data/.hg/undo.branch +0 -1
- data/.hg/undo.dirstate +0 -0
- data/.hgignore +0 -7
- 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?
|
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?
|
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
|
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.
|
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
|
@@ -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
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
22
|
-
|
23
|
-
end
|
22
|
+
parent_node.add_child(node) if node
|
23
|
+
end
|
24
24
|
|
25
|
-
|
26
|
-
add_debug {"=> property order: #{prop_list.to_sentence}"}
|
25
|
+
private
|
27
26
|
|
28
|
-
|
29
|
-
|
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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
-
|
45
|
-
|
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
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
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
|
-
|
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
|
-
|
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
|
-
|
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)
|