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.
- checksums.yaml +5 -5
- data/.travis.yml +8 -15
- data/Gemfile +5 -5
- data/History.txt +0 -80
- data/README.md +1 -0
- data/Rakefile +0 -3
- data/active-fedora.gemspec +8 -7
- data/config/fedora.yml +5 -4
- data/config/predicate_mappings.yml +5 -5
- data/gemfiles/rails4.1.gemfile +10 -0
- data/gemfiles/rails4.2.beta.gemfile +10 -0
- data/lib/active_fedora.rb +151 -117
- data/lib/active_fedora/associations.rb +47 -15
- data/lib/active_fedora/associations/association.rb +29 -8
- data/lib/active_fedora/associations/association_scope.rb +5 -5
- data/lib/active_fedora/associations/belongs_to_association.rb +20 -63
- data/lib/active_fedora/associations/builder/association.rb +61 -25
- data/lib/active_fedora/associations/builder/belongs_to.rb +7 -94
- data/lib/active_fedora/associations/builder/collection_association.rb +11 -43
- data/lib/active_fedora/associations/builder/contains.rb +28 -0
- data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +13 -3
- data/lib/active_fedora/associations/builder/has_many.rb +16 -10
- data/lib/active_fedora/associations/builder/property.rb +14 -0
- data/lib/active_fedora/associations/builder/singular_association.rb +14 -18
- data/lib/active_fedora/associations/builder/singular_property.rb +12 -0
- data/lib/active_fedora/associations/collection_association.rb +57 -80
- data/lib/active_fedora/associations/contains_association.rb +50 -0
- data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +44 -24
- data/lib/active_fedora/associations/has_many_association.rb +46 -14
- data/lib/active_fedora/associations/rdf.rb +86 -0
- data/lib/active_fedora/associations/singular_association.rb +4 -8
- data/lib/active_fedora/associations/singular_rdf.rb +15 -0
- data/lib/active_fedora/attached_files.rb +195 -0
- data/lib/active_fedora/attribute_methods.rb +122 -0
- data/lib/active_fedora/attribute_methods/dirty.rb +16 -0
- data/lib/active_fedora/attribute_methods/read.rb +61 -0
- data/lib/active_fedora/attribute_methods/write.rb +47 -0
- data/lib/active_fedora/attributes.rb +93 -44
- data/lib/active_fedora/attributes/primary_key.rb +12 -0
- data/lib/active_fedora/autosave_association.rb +2 -2
- data/lib/active_fedora/base.rb +16 -15
- data/lib/active_fedora/callbacks.rb +7 -7
- data/lib/active_fedora/change_set.rb +34 -0
- data/lib/active_fedora/cleaner.rb +62 -0
- data/lib/active_fedora/config.rb +4 -22
- data/lib/active_fedora/core.rb +173 -99
- data/lib/active_fedora/datastream.rb +4 -117
- data/lib/active_fedora/datastreams.rb +2 -263
- data/lib/active_fedora/datastreams/nokogiri_datastreams.rb +28 -51
- data/lib/active_fedora/{datastream_attribute.rb → delegated_attribute.rb} +57 -26
- data/lib/active_fedora/errors.rb +61 -0
- data/lib/active_fedora/fedora.rb +19 -0
- data/lib/active_fedora/fedora_attributes.rb +58 -26
- data/lib/active_fedora/file.rb +318 -0
- data/lib/active_fedora/file_configurator.rb +32 -32
- data/lib/active_fedora/file_path_builder.rb +24 -0
- data/lib/active_fedora/files_hash.rb +82 -0
- data/lib/active_fedora/fixity_service.rb +40 -0
- data/lib/active_fedora/indexing.rb +55 -82
- data/lib/active_fedora/indexing_service.rb +70 -0
- data/lib/active_fedora/ldp_resource.rb +26 -0
- data/lib/active_fedora/loadable_from_json.rb +112 -0
- data/lib/active_fedora/model.rb +5 -19
- data/lib/active_fedora/nested_attributes.rb +5 -6
- data/lib/active_fedora/nom_datastream.rb +15 -25
- data/lib/active_fedora/om_datastream.rb +26 -197
- data/lib/active_fedora/persistence.rb +95 -71
- data/lib/active_fedora/predicates.rb +4 -4
- data/lib/active_fedora/qualified_dublin_core_datastream.rb +17 -18
- data/lib/active_fedora/querying.rb +3 -4
- data/lib/active_fedora/railtie.rb +3 -6
- data/lib/active_fedora/rdf.rb +3 -1
- data/lib/active_fedora/rdf/datastream_indexing.rb +11 -0
- data/lib/active_fedora/rdf/fcrepo.rb +10 -324
- data/lib/active_fedora/rdf/indexing.rb +20 -16
- data/lib/active_fedora/rdf/ldp.rb +6 -0
- data/lib/active_fedora/rdf/ntriples_rdf_datastream.rb +1 -1
- data/lib/active_fedora/rdf/persistence.rb +5 -6
- data/lib/active_fedora/rdf/rdf_datastream.rb +44 -37
- data/lib/active_fedora/rdf/rdfxml_datastream.rb +13 -0
- data/lib/active_fedora/rdf/rels_ext.rb +26 -0
- data/lib/active_fedora/reflection.rb +256 -199
- data/lib/active_fedora/relation.rb +18 -6
- data/lib/active_fedora/relation/finder_methods.rb +69 -38
- data/lib/active_fedora/relation/query_methods.rb +7 -3
- data/lib/active_fedora/rspec_matchers/belong_to_associated_active_fedora_object_matcher.rb +7 -7
- data/lib/active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher.rb +8 -8
- data/lib/active_fedora/rspec_matchers/have_predicate_matcher.rb +9 -11
- data/lib/active_fedora/simple_datastream.rb +18 -13
- data/lib/active_fedora/solr_instance_loader.rb +18 -38
- data/lib/active_fedora/solr_service.rb +37 -20
- data/lib/active_fedora/sparql_insert.rb +45 -0
- data/lib/active_fedora/test_support.rb +1 -22
- data/lib/active_fedora/version.rb +1 -1
- data/lib/active_fedora/versionable.rb +90 -0
- data/lib/active_fedora/with_metadata.rb +37 -0
- data/lib/active_fedora/with_metadata/metadata_node.rb +70 -0
- data/lib/generators/active_fedora/config/config_generator.rb +0 -1
- data/lib/generators/active_fedora/config/solr/solr_generator.rb +1 -1
- data/lib/generators/active_fedora/model/model_generator.rb +5 -5
- data/lib/generators/active_fedora/model/templates/datastream_spec.rb.erb +1 -1
- data/lib/generators/active_fedora/model/templates/model_spec.rb.erb +2 -2
- data/lib/tasks/active_fedora_dev.rake +21 -27
- data/spec/config_helper.rb +1 -1
- data/spec/fixtures/mixed_rdf_descMetadata.nt +6 -6
- data/spec/fixtures/rails_root/config/predicate_mappings.yml +3 -19
- data/spec/fixtures/solr_rdf_descMetadata.nt +6 -6
- data/spec/integration/associations_spec.rb +133 -153
- data/spec/integration/attached_files_spec.rb +164 -0
- data/spec/integration/attributes_spec.rb +73 -12
- data/spec/integration/autosave_association_spec.rb +3 -3
- data/spec/integration/base_spec.rb +57 -351
- data/spec/integration/belongs_to_association_spec.rb +86 -76
- data/spec/integration/bug_spec.rb +3 -3
- data/spec/integration/collection_association_spec.rb +4 -4
- data/spec/integration/complex_rdf_datastream_spec.rb +54 -56
- data/spec/integration/delete_all_spec.rb +18 -15
- data/spec/integration/eradicate_spec.rb +54 -0
- data/spec/integration/fedora_solr_sync_spec.rb +7 -5
- data/spec/integration/field_to_solr_name_spec.rb +5 -5
- data/spec/integration/file_fixity_spec.rb +40 -0
- data/spec/integration/file_spec.rb +122 -0
- data/spec/integration/full_featured_model_spec.rb +53 -63
- data/spec/integration/has_and_belongs_to_many_associations_spec.rb +141 -114
- data/spec/integration/has_many_associations_spec.rb +142 -64
- data/spec/integration/json_serialization_spec.rb +50 -8
- data/spec/integration/model_spec.rb +12 -29
- data/spec/integration/nested_attribute_spec.rb +28 -20
- data/spec/integration/ntriples_datastream_spec.rb +60 -57
- data/spec/integration/om_datastream_spec.rb +51 -140
- data/spec/integration/rdf_nested_attributes_spec.rb +16 -14
- data/spec/integration/relation_delegation_spec.rb +7 -9
- data/spec/integration/relation_spec.rb +9 -7
- data/spec/integration/scoped_query_spec.rb +26 -26
- data/spec/integration/solr_instance_loader_spec.rb +69 -53
- data/spec/integration/solr_service_spec.rb +12 -73
- data/spec/integration/versionable_spec.rb +477 -0
- data/spec/integration/with_metadata_spec.rb +52 -0
- data/spec/samples/hydra-mods_article_datastream.rb +10 -6
- data/spec/samples/models/mods_article.rb +6 -2
- data/spec/samples/oral_history_sample.xml +1 -1
- data/spec/samples/oral_history_xml.xml +1 -1
- data/spec/samples/special_thing.rb +3 -3
- data/spec/spec_helper.rb +22 -12
- data/spec/support/an_active_model.rb +3 -7
- data/spec/unit/active_fedora_spec.rb +20 -17
- data/spec/unit/attached_files_spec.rb +203 -0
- data/spec/unit/attributes_spec.rb +286 -207
- data/spec/unit/base_active_model_spec.rb +8 -8
- data/spec/unit/base_datastream_management_spec.rb +11 -24
- data/spec/unit/base_extra_spec.rb +17 -67
- data/spec/unit/base_spec.rb +163 -428
- data/spec/unit/builder/has_and_belongs_to_many_spec.rb +2 -2
- data/spec/unit/callback_spec.rb +38 -23
- data/spec/unit/change_set_spec.rb +46 -0
- data/spec/unit/code_configurator_spec.rb +5 -5
- data/spec/unit/config_spec.rb +9 -14
- data/spec/unit/core_spec.rb +59 -8
- data/spec/unit/file_configurator_spec.rb +55 -53
- data/spec/unit/file_path_builder_spec.rb +18 -0
- data/spec/unit/file_spec.rb +221 -0
- data/spec/unit/files_hash_spec.rb +53 -0
- data/spec/unit/fixity_service_spec.rb +34 -0
- data/spec/unit/has_and_belongs_to_many_association_spec.rb +134 -0
- data/spec/unit/has_many_association_spec.rb +51 -0
- data/spec/unit/indexing_service_spec.rb +23 -0
- data/spec/unit/indexing_spec.rb +26 -0
- data/spec/unit/inheritance_spec.rb +9 -10
- data/spec/unit/model_spec.rb +15 -33
- data/spec/unit/nom_datastream_spec.rb +13 -10
- data/spec/unit/ntriples_datastream_spec.rb +81 -96
- data/spec/unit/om_datastream_spec.rb +137 -227
- data/spec/unit/persistence_spec.rb +28 -34
- data/spec/unit/predicates_spec.rb +29 -29
- data/spec/unit/property_spec.rb +1 -3
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +27 -32
- data/spec/unit/query_spec.rb +116 -149
- data/spec/unit/rdf_datastream_spec.rb +25 -43
- data/spec/unit/rdf_resource_datastream_spec.rb +24 -123
- data/spec/unit/{rdfxml_rdf_datastream_spec.rb → rdfxml_datastream_spec.rb} +21 -25
- data/spec/unit/readonly_spec.rb +23 -0
- data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +6 -6
- data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +6 -6
- data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +6 -6
- data/spec/unit/serializers_spec.rb +1 -1
- data/spec/unit/simple_datastream_spec.rb +12 -23
- data/spec/unit/solr_config_options_spec.rb +14 -17
- data/spec/unit/solr_service_spec.rb +38 -77
- data/spec/unit/sparql_insert_spec.rb +32 -0
- data/spec/unit/validations_spec.rb +8 -11
- metadata +96 -121
- data/lib/active_fedora/auditable.rb +0 -9
- data/lib/active_fedora/content_model.rb +0 -70
- data/lib/active_fedora/datastream_collections.rb +0 -302
- data/lib/active_fedora/datastream_hash.rb +0 -35
- data/lib/active_fedora/digital_object.rb +0 -55
- data/lib/active_fedora/fixture_exporter.rb +0 -33
- data/lib/active_fedora/fixture_loader.rb +0 -48
- data/lib/active_fedora/rdf/identifiable.rb +0 -66
- data/lib/active_fedora/rdf/project_hydra.rb +0 -12
- data/lib/active_fedora/rdf/rdfxml_rdf_datastream.rb +0 -13
- data/lib/active_fedora/rdf_xml_writer.rb +0 -49
- data/lib/active_fedora/relationship_graph.rb +0 -101
- data/lib/active_fedora/reload_on_save.rb +0 -16
- data/lib/active_fedora/rels_ext_datastream.rb +0 -100
- data/lib/active_fedora/rspec_matchers/match_fedora_datastream_matcher.rb +0 -41
- data/lib/active_fedora/rubydora_connection.rb +0 -35
- data/lib/active_fedora/semantic_node.rb +0 -164
- data/lib/active_fedora/service_definitions.rb +0 -88
- data/lib/active_fedora/sharding.rb +0 -58
- data/lib/active_fedora/solr_digital_object.rb +0 -68
- data/lib/active_fedora/unsaved_digital_object.rb +0 -58
- data/lib/generators/active_fedora/config/fedora/fedora_generator.rb +0 -12
- data/lib/generators/active_fedora/config/fedora/templates/fedora.yml +0 -38
- data/lib/generators/active_fedora/config/fedora/templates/fedora_conf/conf/development/fedora.fcfg +0 -953
- data/lib/generators/active_fedora/config/fedora/templates/fedora_conf/conf/test/fedora.fcfg +0 -953
- data/lib/tasks/active_fedora.rake +0 -83
- data/spec/fixtures/sharded_fedora.yml +0 -11
- data/spec/integration/auditable_spec.rb +0 -29
- data/spec/integration/datastream_collections_spec.rb +0 -127
- data/spec/integration/datastream_spec.rb +0 -90
- data/spec/integration/datastreams_spec.rb +0 -173
- data/spec/integration/load_from_solr_spec.rb +0 -66
- data/spec/integration/rels_ext_datastream_spec.rb +0 -82
- data/spec/support/mock_fedora.rb +0 -44
- data/spec/unit/content_model_spec.rb +0 -86
- data/spec/unit/datastream_collections_spec.rb +0 -420
- data/spec/unit/datastream_spec.rb +0 -83
- data/spec/unit/datastreams_spec.rb +0 -243
- data/spec/unit/has_and_belongs_to_many_collection_spec.rb +0 -96
- data/spec/unit/has_many_collection_spec.rb +0 -35
- data/spec/unit/rdf_vocab_spec.rb +0 -30
- data/spec/unit/rdf_xml_writer_spec.rb +0 -63
- data/spec/unit/relationship_graph_spec.rb +0 -115
- data/spec/unit/reload_on_save_spec.rb +0 -24
- data/spec/unit/rels_ext_datastream_spec.rb +0 -170
- data/spec/unit/rspec_matchers/match_fedora_datastream_matcher_spec.rb +0 -44
- data/spec/unit/rubydora_connection_spec.rb +0 -12
- data/spec/unit/semantic_node_spec.rb +0 -112
- data/spec/unit/service_definitions_spec.rb +0 -63
- data/spec/unit/solr_digital_object_spec.rb +0 -97
- data/spec/unit/unsaved_digital_object_spec.rb +0 -48
@@ -1,33 +0,0 @@
|
|
1
|
-
module ActiveFedora
|
2
|
-
module FixtureExporter
|
3
|
-
|
4
|
-
def self.export_to_path(pid, path, extra_params={})
|
5
|
-
foxml = export(pid, extra_params)
|
6
|
-
name = "#{pid.gsub(":","_")}.foxml.xml"
|
7
|
-
filename = File.join(path, name)
|
8
|
-
file = File.new(filename,"w")
|
9
|
-
file.syswrite(foxml)
|
10
|
-
filename
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.export(pid, extra_params={})
|
14
|
-
extra_params = {:format=>:foxml, :context=>:archive}.merge!(extra_params)
|
15
|
-
if extra_params[:format].kind_of?(String)
|
16
|
-
format = extra_params[:format]
|
17
|
-
else
|
18
|
-
format = case extra_params[:format]
|
19
|
-
when :atom then "info:fedora/fedora-system:ATOM-1.1"
|
20
|
-
when :atom_zip then "info:fedora/fedora-system:ATOMZip-1.1"
|
21
|
-
when :mets then "info:fedora/fedora-system:METSFedoraExt-1.1"
|
22
|
-
when :foxml then "info:fedora/fedora-system:FOXML-1.1"
|
23
|
-
else "info:fedora/fedora-system:FOXML-1.1"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
ActiveFedora::Base.connection_for_pid(pid).export(:pid=>pid, :format=>format, :context=>extra_params[:context].to_s)
|
28
|
-
end
|
29
|
-
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
@@ -1,48 +0,0 @@
|
|
1
|
-
module ActiveFedora
|
2
|
-
class FixtureLoader
|
3
|
-
attr_accessor :path
|
4
|
-
|
5
|
-
def initialize(path)
|
6
|
-
self.path = path
|
7
|
-
end
|
8
|
-
|
9
|
-
def filename_for_pid(pid)
|
10
|
-
File.join(path, "#{pid.gsub(":","_")}.foxml.xml")
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.delete(pid)
|
14
|
-
begin
|
15
|
-
ActiveFedora::Base.find(pid, cast: true).delete
|
16
|
-
1
|
17
|
-
rescue ActiveFedora::ObjectNotFoundError
|
18
|
-
ActiveFedora::Base.logger.debug "The object #{pid} has already been deleted (or was never created)." if ActiveFedora::Base.logger
|
19
|
-
0
|
20
|
-
rescue Errno::ECONNREFUSED => e
|
21
|
-
ActiveFedora::Base.logger.debug "Can't connect to Fedora! Are you sure jetty is running?" if ActiveFedora::Base.logger
|
22
|
-
0
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def reload(pid)
|
27
|
-
self.class.delete(pid)
|
28
|
-
import_and_index(pid)
|
29
|
-
end
|
30
|
-
|
31
|
-
def import_and_index(pid)
|
32
|
-
body = self.class.import_to_fedora(filename_for_pid(pid), pid)
|
33
|
-
self.class.index(pid)
|
34
|
-
body
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.index(pid)
|
38
|
-
ActiveFedora::Base.find(pid).update_index
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.import_to_fedora(filename, pid='0')
|
42
|
-
file = File.new(filename, "r")
|
43
|
-
result = ActiveFedora::Base.connection_for_pid(pid).ingest(:file=>file.read)
|
44
|
-
raise "Failed to ingest the fixture." unless result
|
45
|
-
result.body
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
##
|
2
|
-
# This module is included to allow for an ActiveFedora::Base object to be set as the class_name for a Resource.
|
3
|
-
# Enables functionality like:
|
4
|
-
# base = ActiveFedora::Base.new('oregondigital:1')
|
5
|
-
# base.title = 'test'
|
6
|
-
# base.save
|
7
|
-
# subject.descMetadata.set = base
|
8
|
-
# subject.descMetadata.set # => <ActiveFedora::Base>
|
9
|
-
# subject.descMetadata.set.title # => 'test'
|
10
|
-
module ActiveFedora::RDF::Identifiable
|
11
|
-
extend ActiveSupport::Concern
|
12
|
-
delegate :parent, :dump, :query, :rdf_type, :to => :resource
|
13
|
-
|
14
|
-
##
|
15
|
-
# Defines which resource defines this ActiveFedora object.
|
16
|
-
# This is required for ActiveFedora::Rdf::Resource#set_value to append graphs.
|
17
|
-
# If there is no RdfResource, make a dummy one and freeze its graph.
|
18
|
-
def resource
|
19
|
-
return self.send(self.class.resource_datastream).resource unless self.class.resource_datastream.nil?
|
20
|
-
klass = Class.new(ActiveTriples::Resource)
|
21
|
-
klass.send(:include, ActiveFedora::RDF::Persistence)
|
22
|
-
klass.new(ActiveFedora::RDF::Persistence::BASE_URI + self.pid).freeze
|
23
|
-
end
|
24
|
-
|
25
|
-
module ClassMethods
|
26
|
-
##
|
27
|
-
# Returns the datastream whose ActiveFedora::Rdf::Resource is used
|
28
|
-
# for the identifiable object. This supports delegating methods to
|
29
|
-
# the Resource and #from_uri. Defaults to :descMetadata if it
|
30
|
-
# responds to #rdf_subject, otherwise looks for the first
|
31
|
-
# registered datastream that does.
|
32
|
-
def resource_datastream(ds=nil)
|
33
|
-
@resource_datastream ||= ds ? ds : nil
|
34
|
-
return @resource_datastream unless @resource_datastream.nil?
|
35
|
-
return :descMetadata if self.ds_specs['descMetadata'][:type].respond_to? :rdf_subject
|
36
|
-
self.ds_specs.each do |dsid, conf|
|
37
|
-
return dsid.to_sym if conf[:type].respond_to? :rdf_subject
|
38
|
-
end
|
39
|
-
nil
|
40
|
-
end
|
41
|
-
|
42
|
-
##
|
43
|
-
# Finds the appropriate ActiveFedora::Base object given a URI from a graph.
|
44
|
-
# Expected by the API in ActiveFedora::Rdf::Resource
|
45
|
-
# @TODO: Generalize this.
|
46
|
-
# @see ActiveFedora::Rdf::Resource.from_uri
|
47
|
-
# @param [RDF::URI] uri URI that is being looked up.
|
48
|
-
def from_uri(uri,_)
|
49
|
-
begin
|
50
|
-
ActiveFedora::Base.find(pid_from_subject(uri))
|
51
|
-
rescue ActiveFedora::ObjectNotFoundError
|
52
|
-
self.ds_specs[resource_datastream.to_s][:type].resource_class.new(uri)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
##
|
57
|
-
# Finds the pid of an object from its RDF subject, override this
|
58
|
-
# for URI configurations not of form base_uri + pid
|
59
|
-
# @param [RDF::URI] uri URI to convert to pid
|
60
|
-
def pid_from_subject(uri)
|
61
|
-
base_uri = self.ds_specs[resource_datastream.to_s][:type].resource_class.base_uri if resource_datastream
|
62
|
-
base_uri = base_uri || ActiveFedora::RDF::Persistence::BASE_URI
|
63
|
-
uri.to_s.gsub(base_uri, "")
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
require 'rdf'
|
3
|
-
class ActiveFedora::RDF::ProjectHydra < ::RDF::StrictVocabulary("http://projecthydra.org/ns/relations#")
|
4
|
-
property :hasProfile,
|
5
|
-
label: "Has Profile".freeze,
|
6
|
-
subPropertyOf: "info:fedora/fedora-system:def/relations-external#fedoraRelationship".freeze,
|
7
|
-
type: "rdf:Property".freeze
|
8
|
-
property :isGovernedBy,
|
9
|
-
label: "Is Governed By".freeze,
|
10
|
-
subPropertyOf: "info:fedora/fedora-system:def/relations-external#fedoraRelationship".freeze,
|
11
|
-
type: "rdf:Property".freeze
|
12
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'rdf/rdfxml'
|
2
|
-
|
3
|
-
module ActiveFedora
|
4
|
-
# This class ensures that the RELS-EXT datastream is always serialized
|
5
|
-
# with an rdf:Description container for the properties
|
6
|
-
# the default behavior for RDF:RDFXML::Writer is to change that element if
|
7
|
-
# an rdf:type assertion is present; this is incompatible with Fedora 3
|
8
|
-
class RDFXMLWriter < ::RDF::RDFXML::Writer
|
9
|
-
# Display a subject.
|
10
|
-
#
|
11
|
-
# If the Haml template contains an entry matching the subject's rdf:type URI, that entry will be used as the template for this subject and it's properties.
|
12
|
-
#
|
13
|
-
# @example Displays a subject as a Resource Definition:
|
14
|
-
# <div typeof="rdfs:Resource" about="http://example.com/resource">
|
15
|
-
# <h1 property="dc:title">label</h1>
|
16
|
-
# <ul>
|
17
|
-
# <li content="2009-04-30T06:15:51Z" property="dc:created">2009-04-30T06:15:51+00:00</li>
|
18
|
-
# </ul>
|
19
|
-
# </div>
|
20
|
-
#
|
21
|
-
# @param [RDF::Resource] subject
|
22
|
-
# @param [Hash{Symbol => Object}] options
|
23
|
-
# @option options [:li, nil] :element(:div)
|
24
|
-
# Serialize using <li> rather than template default element
|
25
|
-
# @option options [RDF::Resource] :rel (nil)
|
26
|
-
# Optional @rel property
|
27
|
-
# @return [Nokogiri::XML::Element, {Namespace}]
|
28
|
-
#
|
29
|
-
def subject(subject, options = {})
|
30
|
-
return if is_done?(subject)
|
31
|
-
|
32
|
-
subject_done(subject)
|
33
|
-
|
34
|
-
properties = properties_for_subject(subject)
|
35
|
-
typeof = type_of(properties[::RDF.type.to_s], subject)
|
36
|
-
prop_list = order_properties(properties)
|
37
|
-
|
38
|
-
add_debug {"subject: #{curie.inspect}, typeof: #{typeof.inspect}, props: #{prop_list.inspect}"}
|
39
|
-
|
40
|
-
render_opts = {:typeof => typeof, :property_values => properties}.merge(options)
|
41
|
-
|
42
|
-
render_subject_template(subject, prop_list, render_opts)
|
43
|
-
end
|
44
|
-
|
45
|
-
def type_of(type, subject)
|
46
|
-
""
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,101 +0,0 @@
|
|
1
|
-
module ActiveFedora
|
2
|
-
class RelationshipGraph
|
3
|
-
|
4
|
-
attr_accessor :relationships, :dirty
|
5
|
-
|
6
|
-
def initialize
|
7
|
-
self.dirty = false
|
8
|
-
self.relationships = Hash.new { |h, k| h[k] = [] }
|
9
|
-
end
|
10
|
-
|
11
|
-
def has_predicate?(predicate)
|
12
|
-
relationships.has_key? uri_predicate(predicate)
|
13
|
-
end
|
14
|
-
|
15
|
-
def add(predicate, object, literal=false)
|
16
|
-
uri = uri_predicate(predicate)
|
17
|
-
unless has_predicate? uri
|
18
|
-
relationships[uri] = []
|
19
|
-
end
|
20
|
-
object = ::RDF::Literal.new(object) if literal
|
21
|
-
unless relationships[uri].include?(object)
|
22
|
-
@dirty = true
|
23
|
-
relationships[uri] << object
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
# Remove the statement matching the predicate and object
|
28
|
-
# @param predicate [Symbol, URI] the predicate to delete
|
29
|
-
# @param object the object to delete, if nil, all statements with this predicate are deleted.
|
30
|
-
def delete(predicate, object = nil)
|
31
|
-
uri = uri_predicate(predicate)
|
32
|
-
return unless has_predicate? uri
|
33
|
-
if object.nil?
|
34
|
-
@dirty = true
|
35
|
-
relationships.delete(uri)
|
36
|
-
return
|
37
|
-
end
|
38
|
-
if relationships[uri].include?(object)
|
39
|
-
@dirty = true
|
40
|
-
relationships[uri].delete(object)
|
41
|
-
end
|
42
|
-
if object.respond_to?(:internal_uri) && relationships[uri].include?(object.internal_uri)
|
43
|
-
@dirty = true
|
44
|
-
relationships[uri].delete(object.internal_uri)
|
45
|
-
elsif object.is_a? String
|
46
|
-
relationships[uri].delete_if{|obj| obj.respond_to?(:internal_uri) && obj.internal_uri == object}
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def [](predicate)
|
51
|
-
uri = uri_predicate(predicate)
|
52
|
-
relationships[uri]
|
53
|
-
end
|
54
|
-
|
55
|
-
def to_graph(subject_uri)
|
56
|
-
# need to destroy relationships and rewrite it.
|
57
|
-
subject = ::RDF::URI.new(subject_uri)
|
58
|
-
graph = ::RDF::Graph.new
|
59
|
-
relationships.each do |predicate, values|
|
60
|
-
values.each do |object|
|
61
|
-
graph.insert build_statement(subject, predicate, object)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
graph
|
66
|
-
end
|
67
|
-
|
68
|
-
# Create an RDF statement
|
69
|
-
# @param uri a string represending the subject
|
70
|
-
# @param predicate [Symbol, URI] a predicate
|
71
|
-
# @param target an object to store
|
72
|
-
def build_statement(uri, predicate, target)
|
73
|
-
raise "Not allowed anymore" if uri == :self
|
74
|
-
target = target.internal_uri if target.respond_to? :internal_uri
|
75
|
-
subject = ::RDF::URI.new(uri) #TODO cache
|
76
|
-
if target.is_a? ::RDF::Literal or target.is_a? ::RDF::Resource
|
77
|
-
object = target
|
78
|
-
else
|
79
|
-
begin
|
80
|
-
target_uri = (target.is_a? URI) ? target : URI.parse(target)
|
81
|
-
if target_uri.scheme.nil?
|
82
|
-
raise ArgumentError, "Invalid target \"#{target}\". Must have namespace."
|
83
|
-
end
|
84
|
-
if target_uri.to_s =~ /\A[\w\-]+:[\w\-]+\Z/
|
85
|
-
raise ArgumentError, "Invalid target \"#{target}\". Target should be a complete URI, and not a pid."
|
86
|
-
end
|
87
|
-
rescue URI::InvalidURIError
|
88
|
-
raise ArgumentError, "Invalid target \"#{target}\". Target must be specified as a literal, or be a valid URI."
|
89
|
-
end
|
90
|
-
object = ::RDF::URI.new(target)
|
91
|
-
end
|
92
|
-
::RDF::Statement.new(subject, uri_predicate(predicate), object)
|
93
|
-
|
94
|
-
end
|
95
|
-
|
96
|
-
def uri_predicate(predicate)
|
97
|
-
return predicate if predicate.kind_of? ::RDF::URI
|
98
|
-
ActiveFedora::Predicates.find_graph_predicate(predicate)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
@@ -1,100 +0,0 @@
|
|
1
|
-
require 'uri'
|
2
|
-
require 'rdf/rdfxml'
|
3
|
-
require 'active_fedora/rdf_xml_writer'
|
4
|
-
|
5
|
-
module ActiveFedora
|
6
|
-
class RelsExtDatastream < Datastream
|
7
|
-
|
8
|
-
attr_accessor :model
|
9
|
-
delegate :relationships, to: :model
|
10
|
-
|
11
|
-
def self.default_attributes
|
12
|
-
super.merge(:controlGroup => 'X', :mimeType => 'application/rdf+xml')
|
13
|
-
end
|
14
|
-
|
15
|
-
def changed?
|
16
|
-
model.relationships_are_dirty? or super
|
17
|
-
end
|
18
|
-
|
19
|
-
def metadata?
|
20
|
-
true
|
21
|
-
end
|
22
|
-
|
23
|
-
def serialize!
|
24
|
-
self.content = to_rels_ext() if model.relationships_are_dirty?
|
25
|
-
model.relationships_are_not_dirty!
|
26
|
-
end
|
27
|
-
|
28
|
-
# Populate a RelsExtDatastream object based on the "datastream" content
|
29
|
-
# Assumes that the datastream contains RDF XML from a Fedora RELS-EXT datastream
|
30
|
-
# @param [String] xml the "rdf" node
|
31
|
-
# @param [ActiveFedora::Datastream] tmpl the Datastream object that you are populating
|
32
|
-
def self.from_xml(xml, tmpl)
|
33
|
-
if (xml.nil?)
|
34
|
-
### maybe put the template here?
|
35
|
-
else
|
36
|
-
ensure_predicates_exist!(xml)
|
37
|
-
tmpl.model.relationships = xml
|
38
|
-
tmpl
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
# Creates a RELS-EXT datastream for insertion into a Fedora Object
|
43
|
-
def to_rels_ext()
|
44
|
-
xml = ActiveFedora::RDFXMLWriter.buffer do |writer|
|
45
|
-
writer.prefixes.merge! ActiveFedora::Predicates.predicate_namespaces
|
46
|
-
relationships.each_statement do |statement|
|
47
|
-
writer << statement
|
48
|
-
end
|
49
|
-
end
|
50
|
-
xml
|
51
|
-
end
|
52
|
-
|
53
|
-
def self.ensure_predicates_exist!(xml)
|
54
|
-
statements = Nokogiri::XML(xml).xpath('//rdf:Description/*', 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#')
|
55
|
-
predicates = statements.collect { |e| { :prefix => e.namespace.prefix, :uri => e.namespace.href, :predicate => e.name } }.uniq
|
56
|
-
predicates.each do |pred|
|
57
|
-
unless Predicates.predicate_mappings[pred[:uri]]
|
58
|
-
Predicates.predicate_mappings[pred[:uri]] = {}
|
59
|
-
if pred[:prefix] and not Predicates.predicate_namespaces.has_value?(pred[:uri])
|
60
|
-
Predicates.predicate_namespaces[pred[:prefix].to_sym] = pred[:uri]
|
61
|
-
end
|
62
|
-
end
|
63
|
-
ns = Predicates.predicate_mappings[pred[:uri]]
|
64
|
-
unless ns.invert[pred[:predicate]]
|
65
|
-
ns["#{pred[:prefix]}_#{pred[:predicate].underscore}".to_sym] = pred[:predicate]
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
# ** EXPERIMENTAL **
|
71
|
-
#
|
72
|
-
# This is utilized by ActiveFedora::Base.load_instance_from_solr to load
|
73
|
-
# the relationships hash using the Solr document passed in instead of from the RELS-EXT datastream
|
74
|
-
# in Fedora. Utilizes solr_name method (provided by Solrizer::FieldMapper) to map solr key to
|
75
|
-
# relationship predicate.
|
76
|
-
#
|
77
|
-
# ====Warning
|
78
|
-
# Solr must be synchronized with RELS-EXT data in Fedora.
|
79
|
-
def from_solr(solr_doc)
|
80
|
-
#cycle through all possible predicates
|
81
|
-
model.relationships_loaded = true
|
82
|
-
Predicates.predicate_mappings.each_pair do |namespace,predicates|
|
83
|
-
predicates.keys.each do |predicate|
|
84
|
-
predicate_symbol = ActiveFedora::SolrService.solr_name(predicate, :symbol)
|
85
|
-
value = (solr_doc[predicate_symbol].nil? ? solr_doc[predicate_symbol.to_s]: solr_doc[predicate_symbol])
|
86
|
-
unless value.nil?
|
87
|
-
if value.is_a? Array
|
88
|
-
value.each do |obj|
|
89
|
-
model.add_relationship(predicate, obj)
|
90
|
-
end
|
91
|
-
else
|
92
|
-
model.add_relationship(predicate, value)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
@load_from_solr = true
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|