active-fedora 9.12.0 → 9.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/active-fedora.gemspec +1 -0
- data/lib/active_fedora.rb +1 -0
- data/lib/active_fedora/associations.rb +38 -3
- data/lib/active_fedora/associations/basic_contains_association.rb +12 -51
- data/lib/active_fedora/associations/builder/aggregation.rb +1 -1
- data/lib/active_fedora/associations/builder/basic_contains.rb +7 -0
- data/lib/active_fedora/associations/builder/{contains.rb → has_subresource.rb} +2 -2
- data/lib/active_fedora/associations/contains_association.rb +19 -1
- data/lib/active_fedora/associations/directly_contains_association.rb +1 -15
- data/lib/active_fedora/associations/has_subresource_association.rb +61 -0
- data/lib/active_fedora/attached_files.rb +6 -9
- data/lib/active_fedora/autosave_association.rb +1 -1
- data/lib/active_fedora/base.rb +0 -1
- data/lib/active_fedora/common.rb +1 -0
- data/lib/active_fedora/fedora.rb +14 -19
- data/lib/active_fedora/file.rb +1 -1
- data/lib/active_fedora/file/attributes.rb +4 -0
- data/lib/active_fedora/file_persistence.rb +9 -1
- data/lib/active_fedora/initializing_connection.rb +64 -0
- data/lib/active_fedora/ldp_cache.rb +1 -2
- data/lib/active_fedora/ldp_resource_service.rb +7 -1
- data/lib/active_fedora/persistence.rb +12 -1
- data/lib/active_fedora/reflection.rb +22 -6
- data/lib/active_fedora/simple_datastream.rb +2 -0
- data/lib/active_fedora/version.rb +1 -1
- data/lib/generators/active_fedora/config/fedora/fedora_generator.rb +1 -0
- data/lib/generators/active_fedora/config/fedora/templates/.fcrepo_wrapper +1 -0
- data/lib/generators/active_fedora/config/fedora/templates/fcrepo_wrapper_test.yml +4 -0
- data/lib/generators/active_fedora/config/solr/solr_generator.rb +1 -0
- data/lib/generators/active_fedora/config/solr/templates/.solr_wrapper +3 -0
- data/lib/generators/active_fedora/config/solr/templates/solr_wrapper_test.yml +8 -0
- data/spec/integration/attached_files_spec.rb +77 -18
- data/spec/integration/attributes_spec.rb +3 -4
- data/spec/integration/autosave_association_spec.rb +0 -1
- data/spec/integration/base_spec.rb +19 -66
- data/spec/integration/basic_contains_association_spec.rb +108 -0
- data/spec/integration/complex_rdf_datastream_spec.rb +1 -1
- data/spec/integration/field_to_solr_name_spec.rb +12 -11
- data/spec/integration/file_fixity_spec.rb +1 -1
- data/spec/integration/file_spec.rb +4 -1
- data/spec/integration/generators/fedora_generator_spec.rb +26 -0
- data/spec/integration/generators/solr_generator_spec.rb +26 -0
- data/spec/integration/has_and_belongs_to_many_associations_spec.rb +6 -16
- data/spec/integration/has_many_associations_spec.rb +6 -16
- data/spec/integration/{contains_association_spec.rb → has_subresource_spec.rb} +1 -1
- data/spec/integration/json_serialization_spec.rb +11 -5
- data/spec/integration/model_spec.rb +7 -13
- data/spec/integration/ntriples_datastream_spec.rb +2 -2
- data/spec/integration/om_datastream_spec.rb +1 -1
- data/spec/integration/persistence_spec.rb +0 -3
- data/spec/integration/query_result_builder_spec.rb +1 -1
- data/spec/integration/relation_delegation_spec.rb +3 -8
- data/spec/integration/scoped_query_spec.rb +5 -7
- data/spec/integration/solr_hit_spec.rb +10 -4
- data/spec/integration/solr_instance_loader_spec.rb +11 -4
- data/spec/integration/versionable_spec.rb +3 -3
- data/spec/spec_helper.rb +5 -1
- data/spec/unit/active_fedora_spec.rb +1 -1
- data/spec/unit/attached_files_spec.rb +32 -21
- data/spec/unit/attributes_spec.rb +21 -23
- data/spec/unit/base_active_model_spec.rb +13 -10
- data/spec/unit/base_spec.rb +2 -24
- data/spec/unit/callback_spec.rb +0 -8
- data/spec/unit/core_spec.rb +3 -5
- data/spec/unit/inheritance_spec.rb +15 -9
- data/spec/unit/ntriples_datastream_spec.rb +1 -1
- data/spec/unit/om_datastream_spec.rb +1 -1
- data/spec/unit/persistence_spec.rb +21 -0
- data/spec/unit/query_spec.rb +8 -0
- data/spec/unit/rdf_datastream_spec.rb +1 -1
- data/spec/unit/rdf_resource_datastream_spec.rb +1 -1
- data/spec/unit/simple_datastream_spec.rb +8 -2
- data/spec/unit/solr_config_options_spec.rb +1 -1
- data/spec/unit/validations_spec.rb +2 -8
- metadata +27 -6
- data/spec/integration/bug_spec.rb +0 -40
- data/spec/integration/full_featured_model_spec.rb +0 -160
data/lib/active_fedora/file.rb
CHANGED
@@ -203,7 +203,7 @@ module ActiveFedora
|
|
203
203
|
end
|
204
204
|
|
205
205
|
def build_ldp_resource_via_uri(uri = nil, content = '')
|
206
|
-
Ldp::Resource::BinarySource.new(ldp_connection, uri, content,
|
206
|
+
Ldp::Resource::BinarySource.new(ldp_connection, uri, content, base_path_for_resource)
|
207
207
|
end
|
208
208
|
|
209
209
|
def uploaded_file?(payload)
|
@@ -8,7 +8,7 @@ module ActiveFedora
|
|
8
8
|
|
9
9
|
def _create_record(_options = {})
|
10
10
|
return false if content.nil?
|
11
|
-
ldp_source
|
11
|
+
@ldp_source = build_ldp_binary_source
|
12
12
|
ldp_source.create do |req|
|
13
13
|
req.headers.merge!(ldp_headers)
|
14
14
|
end
|
@@ -23,5 +23,13 @@ module ActiveFedora
|
|
23
23
|
end
|
24
24
|
refresh
|
25
25
|
end
|
26
|
+
|
27
|
+
def build_ldp_binary_source
|
28
|
+
if id
|
29
|
+
build_ldp_resource_via_uri(uri, content)
|
30
|
+
else
|
31
|
+
build_ldp_resource_via_uri(nil, content)
|
32
|
+
end
|
33
|
+
end
|
26
34
|
end
|
27
35
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module ActiveFedora
|
2
|
+
class InitializingConnection < Delegator
|
3
|
+
attr_reader :connection, :root_resource_path
|
4
|
+
|
5
|
+
def initialize(connection, root_resource_path)
|
6
|
+
super(connection)
|
7
|
+
@connection = connection
|
8
|
+
@root_resource_path = root_resource_path
|
9
|
+
@initialized = false
|
10
|
+
end
|
11
|
+
|
12
|
+
def __getobj__
|
13
|
+
@connection
|
14
|
+
end
|
15
|
+
|
16
|
+
def __setobj__(connection)
|
17
|
+
@connection = connection
|
18
|
+
end
|
19
|
+
|
20
|
+
def head(*)
|
21
|
+
init_base_path
|
22
|
+
super
|
23
|
+
end
|
24
|
+
|
25
|
+
def get(*)
|
26
|
+
init_base_path
|
27
|
+
super
|
28
|
+
end
|
29
|
+
|
30
|
+
def delete(*)
|
31
|
+
init_base_path
|
32
|
+
super
|
33
|
+
end
|
34
|
+
|
35
|
+
def post(*)
|
36
|
+
init_base_path
|
37
|
+
super
|
38
|
+
end
|
39
|
+
|
40
|
+
def put(*)
|
41
|
+
init_base_path
|
42
|
+
super
|
43
|
+
end
|
44
|
+
|
45
|
+
def patch(*)
|
46
|
+
init_base_path
|
47
|
+
super
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
# Call this to create a Container Resource to act as the base path for this connection
|
53
|
+
def init_base_path
|
54
|
+
return if @initialized
|
55
|
+
|
56
|
+
connection.head(root_resource_path)
|
57
|
+
ActiveFedora::Base.logger.info "Attempted to init base path `#{root_resource_path}`, but it already exists" if ActiveFedora::Base.logger
|
58
|
+
@initialized = true
|
59
|
+
false
|
60
|
+
rescue Ldp::NotFound
|
61
|
+
@initialized = connection.put(root_resource_path, '').success?
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -10,10 +10,16 @@ module ActiveFedora
|
|
10
10
|
if id
|
11
11
|
LdpResource.new(connection, to_uri(klass, id))
|
12
12
|
else
|
13
|
-
|
13
|
+
parent_uri = ActiveFedora.fedora.host + ActiveFedora.fedora.base_path
|
14
|
+
LdpResource.new(connection, nil, nil, parent_uri)
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
18
|
+
def build_resource_under_path(graph, parent_uri)
|
19
|
+
parent_uri ||= ActiveFedora.fedora.host + ActiveFedora.fedora.base_path
|
20
|
+
LdpResource.new(connection, nil, graph, parent_uri)
|
21
|
+
end
|
22
|
+
|
17
23
|
def update(change_set, klass, id)
|
18
24
|
SparqlInsert.new(change_set.changes).execute(to_uri(klass, id))
|
19
25
|
end
|
@@ -5,6 +5,8 @@ module ActiveFedora
|
|
5
5
|
|
6
6
|
def new_record?
|
7
7
|
@ldp_source.new?
|
8
|
+
rescue Ldp::Gone
|
9
|
+
false
|
8
10
|
end
|
9
11
|
|
10
12
|
def persisted?
|
@@ -85,6 +87,11 @@ module ActiveFedora
|
|
85
87
|
self.class.eradicate(id)
|
86
88
|
end
|
87
89
|
|
90
|
+
# Used when setting containment
|
91
|
+
def base_path_for_resource=(path)
|
92
|
+
@base_path = path
|
93
|
+
end
|
94
|
+
|
88
95
|
module ClassMethods
|
89
96
|
# Creates an object (or multiple objects) and saves it to the repository, if validations pass.
|
90
97
|
# The resulting object is returned whether the object was saved successfully to the repository or not.
|
@@ -199,11 +206,15 @@ module ActiveFedora
|
|
199
206
|
@ldp_source = if !id && new_id = assign_id
|
200
207
|
LdpResource.new(ActiveFedora.fedora.connection, self.class.id_to_uri(new_id), @resource)
|
201
208
|
else
|
202
|
-
LdpResource.new(ActiveFedora.fedora.connection, @ldp_source.subject, @resource,
|
209
|
+
LdpResource.new(ActiveFedora.fedora.connection, @ldp_source.subject, @resource, base_path_for_resource)
|
203
210
|
end
|
204
211
|
end
|
205
212
|
|
206
213
|
def base_path_for_resource
|
214
|
+
@base_path ||= ActiveFedora.fedora.host + default_base_path_for_resource
|
215
|
+
end
|
216
|
+
|
217
|
+
def default_base_path_for_resource
|
207
218
|
init_root_path if has_uri_prefix?
|
208
219
|
root_resource_path
|
209
220
|
end
|
@@ -20,14 +20,16 @@ module ActiveFedora
|
|
20
20
|
BelongsToReflection
|
21
21
|
when :has_and_belongs_to_many
|
22
22
|
HasAndBelongsToManyReflection
|
23
|
-
when :
|
24
|
-
|
23
|
+
when :has_subresource
|
24
|
+
HasSubresourceReflection
|
25
25
|
when :directly_contains
|
26
26
|
DirectlyContainsReflection
|
27
27
|
when :directly_contains_one
|
28
28
|
DirectlyContainsOneReflection
|
29
29
|
when :indirectly_contains
|
30
30
|
IndirectlyContainsReflection
|
31
|
+
when :is_a_container
|
32
|
+
BasicContainsReflection
|
31
33
|
when :rdf
|
32
34
|
RDFPropertyReflection
|
33
35
|
when :singular_rdf
|
@@ -107,11 +109,11 @@ module ActiveFedora
|
|
107
109
|
end
|
108
110
|
|
109
111
|
def child_resource_reflections
|
110
|
-
reflect_on_all_associations(:
|
112
|
+
reflect_on_all_associations(:has_subresource).select { |_, reflection| reflection.klass <= ActiveFedora::File }
|
111
113
|
end
|
112
114
|
|
113
115
|
def contained_rdf_source_reflections
|
114
|
-
reflect_on_all_associations(:
|
116
|
+
reflect_on_all_associations(:has_subresource).select { |_, reflection| !(reflection.klass <= ActiveFedora::File) }
|
115
117
|
end
|
116
118
|
|
117
119
|
# Returns the AssociationReflection object for the +association+ (use the symbol).
|
@@ -503,9 +505,23 @@ module ActiveFedora
|
|
503
505
|
end
|
504
506
|
end
|
505
507
|
|
506
|
-
class
|
508
|
+
class HasSubresourceReflection < AssociationReflection # :nodoc:
|
507
509
|
def macro
|
508
|
-
:
|
510
|
+
:has_subresource
|
511
|
+
end
|
512
|
+
|
513
|
+
def association_class
|
514
|
+
Associations::HasSubresourceAssociation
|
515
|
+
end
|
516
|
+
end
|
517
|
+
|
518
|
+
class BasicContainsReflection < AssociationReflection # :nodoc:
|
519
|
+
def macro
|
520
|
+
:is_a_container
|
521
|
+
end
|
522
|
+
|
523
|
+
def collection?
|
524
|
+
true
|
509
525
|
end
|
510
526
|
|
511
527
|
def association_class
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module ActiveFedora
|
2
2
|
# This class represents a simple xml datastream.
|
3
3
|
class SimpleDatastream < OmDatastream
|
4
|
+
extend Deprecation
|
4
5
|
class_attribute :class_fields
|
5
6
|
attr_accessor :fields
|
6
7
|
self.class_fields = []
|
@@ -18,6 +19,7 @@ module ActiveFedora
|
|
18
19
|
# Constructor. this class will call self.field for each DCTERM. In short, all DCTERMS fields will already exist
|
19
20
|
# when this method returns. Each term is marked as a multivalue string.
|
20
21
|
def initialize(digital_object = nil, dsid = nil, options = {}, &block)
|
22
|
+
Deprecation.warn(SimpleDatastream, "ActiveFedora::SimpleDatastream is deprecated and will be removed in ActiveFedora 10.0")
|
21
23
|
self.fields = {}
|
22
24
|
super
|
23
25
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActiveFedora::AttachedFiles do
|
4
|
-
describe "#
|
4
|
+
describe "#has_subresource" do
|
5
5
|
before do
|
6
6
|
class FooHistory < ActiveFedora::Base
|
7
|
-
|
7
|
+
has_subresource 'child'
|
8
8
|
end
|
9
9
|
end
|
10
10
|
after do
|
@@ -25,32 +25,91 @@ describe ActiveFedora::AttachedFiles do
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
|
29
|
+
describe "#has_metadata" do
|
30
|
+
describe "autosave" do
|
31
|
+
before :each do
|
32
|
+
class MockAFBaseRelationship < ActiveFedora::Base
|
33
|
+
extend Deprecation
|
34
|
+
Deprecation.silence(MockAFBaseRelationship) do
|
35
|
+
has_metadata 'foo', type: Hydra::ModsArticleDatastream
|
36
|
+
end
|
37
|
+
end
|
33
38
|
end
|
34
|
-
|
39
|
+
after :each do
|
40
|
+
Object.send(:remove_const, :MockAFBaseRelationship)
|
41
|
+
end
|
42
|
+
describe "a new document" do
|
43
|
+
before do
|
44
|
+
@obj = MockAFBaseRelationship.new
|
35
45
|
|
36
|
-
|
37
|
-
|
46
|
+
@obj.foo.person = "bob"
|
47
|
+
@obj.save
|
48
|
+
end
|
49
|
+
|
50
|
+
it "saves the datastream." do
|
51
|
+
obj = MockAFBaseRelationship.find(@obj.id)
|
52
|
+
expect(obj.foo).to_not be_new_record
|
53
|
+
expect(obj.foo.person).to eq ['bob']
|
54
|
+
person_field = ActiveFedora.index_field_mapper.solr_name('foo__person', type: :string)
|
55
|
+
solr_result = ActiveFedora::SolrService.query("{!field f=id}#{@obj.id}", fl: "id #{person_field}").first
|
56
|
+
expect(solr_result).to eq("id" => @obj.id, person_field => ['bob'])
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "that already exists in the repo" do
|
61
|
+
before do
|
62
|
+
@release = MockAFBaseRelationship.create
|
63
|
+
@release.foo.person = "test foo content"
|
64
|
+
@release.save
|
65
|
+
end
|
66
|
+
describe "and has been changed" do
|
67
|
+
before do
|
68
|
+
@release.foo.person = 'frank'
|
69
|
+
@release.save!
|
70
|
+
end
|
71
|
+
it "saves the datastream." do
|
72
|
+
expect(MockAFBaseRelationship.find(@release.id).foo.person).to eq ['frank']
|
73
|
+
person_field = ActiveFedora.index_field_mapper.solr_name('foo__person', type: :string)
|
74
|
+
expect(ActiveFedora::SolrService.query("id:\"#{@release.id}\"", fl: "id #{person_field}").first).to eq("id" => @release.id, person_field => ['frank'])
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
38
78
|
end
|
39
79
|
|
40
|
-
|
80
|
+
describe "serializing datastreams" do
|
81
|
+
before do
|
82
|
+
class TestingMetadataSerializing < ActiveFedora::Base
|
83
|
+
extend Deprecation
|
84
|
+
Deprecation.silence(TestingMetadataSerializing) do
|
85
|
+
has_metadata "nokogiri_autocreate_on", autocreate: true, type: ActiveFedora::OmDatastream
|
86
|
+
has_metadata "nokogiri_autocreate_off", autocreate: false, type: ActiveFedora::OmDatastream
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
41
90
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
91
|
+
after do
|
92
|
+
Object.send(:remove_const, :TestingMetadataSerializing)
|
93
|
+
end
|
94
|
+
|
95
|
+
subject { TestingMetadataSerializing.new }
|
96
|
+
|
97
|
+
it "works" do
|
98
|
+
subject.save(validate: false)
|
99
|
+
expect(subject.nokogiri_autocreate_on).to_not be_new_record
|
100
|
+
expect(subject.nokogiri_autocreate_off).to be_new_record
|
101
|
+
end
|
46
102
|
end
|
47
103
|
end
|
48
104
|
|
49
105
|
describe "#has_file_datastream" do
|
50
106
|
before do
|
51
107
|
class HasFile < ActiveFedora::Base
|
52
|
-
|
53
|
-
|
108
|
+
extend Deprecation
|
109
|
+
Deprecation.silence(HasFile) do
|
110
|
+
has_file_datastream "file_ds"
|
111
|
+
has_file_datastream "file_ds2", autocreate: false
|
112
|
+
end
|
54
113
|
end
|
55
114
|
end
|
56
115
|
|
@@ -127,7 +186,7 @@ describe ActiveFedora::AttachedFiles do
|
|
127
186
|
end
|
128
187
|
|
129
188
|
describe ".metadata_streams" do
|
130
|
-
let(:mds1) { ActiveFedora::
|
189
|
+
let(:mds1) { ActiveFedora::QualifiedDublinCoreDatastream.new }
|
131
190
|
let(:mds2) { ActiveFedora::QualifiedDublinCoreDatastream.new }
|
132
191
|
let(:fds) { ActiveFedora::File.new }
|
133
192
|
before do
|
@@ -10,15 +10,14 @@ describe "delegating attributes" do
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
class TitledObject < ActiveFedora::Base
|
13
|
-
|
14
|
-
m.field "title", :string
|
15
|
-
end
|
13
|
+
has_subresource 'foo', class_name: 'ActiveFedora::QualifiedDublinCoreDatastream'
|
16
14
|
Deprecation.silence(ActiveFedora::Attributes) do
|
17
15
|
has_attributes :title, datastream: 'foo', multiple: false
|
18
16
|
end
|
19
17
|
end
|
18
|
+
|
20
19
|
class RdfObject < ActiveFedora::Base
|
21
|
-
|
20
|
+
has_subresource 'foo', class_name: 'PropertiesDatastream'
|
22
21
|
Deprecation.silence(ActiveFedora::Attributes) do
|
23
22
|
has_attributes :depositor, datastream: :foo, multiple: false do |index|
|
24
23
|
index.as :stored_searchable
|