active-fedora 12.0.0 → 12.1.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 +5 -5
- data/.rubocop.yml +7 -7
- data/.rubocop_todo.yml +10 -100
- data/.travis.yml +10 -4
- data/CODE_OF_CONDUCT.md +36 -0
- data/CONTRIBUTING.md +23 -21
- data/History.txt +29 -29
- data/LICENSE +16 -14
- data/README.md +40 -29
- data/SUPPORT.md +5 -0
- data/active-fedora.gemspec +7 -7
- data/lib/active_fedora/aggregation/list_source.rb +3 -2
- data/lib/active_fedora/associations/builder/collection_association.rb +1 -0
- data/lib/active_fedora/associations/collection_association.rb +3 -0
- data/lib/active_fedora/associations/collection_proxy.rb +2 -0
- data/lib/active_fedora/associations/directly_contains_one_association.rb +1 -0
- data/lib/active_fedora/associations/indirectly_contains_association.rb +2 -0
- data/lib/active_fedora/associations/singular_association.rb +1 -0
- data/lib/active_fedora/attribute_methods/read.rb +1 -1
- data/lib/active_fedora/attribute_methods/write.rb +1 -1
- data/lib/active_fedora/attribute_methods.rb +1 -1
- data/lib/active_fedora/attributes/property_builder.rb +1 -0
- data/lib/active_fedora/attributes.rb +1 -1
- data/lib/active_fedora/callbacks.rb +7 -2
- data/lib/active_fedora/fedora.rb +8 -0
- data/lib/active_fedora/file.rb +4 -4
- data/lib/active_fedora/indexing/descendant_fetcher.rb +1 -1
- data/lib/active_fedora/indexing/field_mapper.rb +2 -0
- data/lib/active_fedora/indexing/suffix.rb +3 -1
- data/lib/active_fedora/inheritable_accessors.rb +1 -0
- data/lib/active_fedora/loadable_from_json.rb +1 -0
- data/lib/active_fedora/nested_attributes.rb +1 -0
- data/lib/active_fedora/persistence/null_identifier_service.rb +11 -0
- data/lib/active_fedora/persistence.rb +14 -1
- data/lib/active_fedora/reflection.rb +1 -1
- data/lib/active_fedora/relation/delegation.rb +2 -1
- data/lib/active_fedora/relation/finder_methods.rb +6 -1
- data/lib/active_fedora/relation/merger.rb +1 -0
- data/lib/active_fedora/relation.rb +14 -0
- data/lib/active_fedora/validations.rb +7 -0
- data/lib/active_fedora/version.rb +1 -1
- data/lib/active_fedora/with_metadata/metadata_node.rb +2 -1
- data/lib/active_fedora/with_metadata.rb +1 -0
- data/lib/active_fedora.rb +1 -1
- data/lib/generators/active_fedora/config/fedora/fedora_generator.rb +1 -1
- data/lib/generators/active_fedora/config/solr/solr_generator.rb +2 -1
- data/lib/generators/active_fedora/config/solr/templates/solr/config/schema.xml +64 -51
- data/lib/generators/active_fedora/config/solr/templates/solr/config/solrconfig.xml +4 -1
- data/lib/generators/active_fedora/model/templates/datastream.rb.erb +1 -1
- data/spec/integration/file_spec.rb +1 -1
- data/spec/integration/generators/fedora_generator_spec.rb +1 -1
- data/spec/integration/generators/solr_generator_spec.rb +1 -1
- data/spec/integration/relation_spec.rb +43 -0
- data/spec/spec_helper.rb +10 -8
- data/spec/support/an_active_model.rb +4 -0
- data/spec/unit/callback_spec.rb +8 -1
- data/spec/unit/finder_methods_spec.rb +47 -1
- data/spec/unit/validations_spec.rb +18 -0
- metadata +29 -21
- /data/lib/generators/active_fedora/config/fedora/templates/{.fcrepo_wrapper → .fcrepo_wrapper.yml} +0 -0
- /data/lib/generators/active_fedora/config/solr/templates/{.solr_wrapper → .solr_wrapper.yml} +0 -0
data/README.md
CHANGED
|
@@ -1,40 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
-----------
|
|
1
|
+
# ActiveFedora
|
|
3
2
|
|
|
4
|
-
[](http://badge.fury.io/rb/active-fedora)
|
|
4
|
+
[](https://travis-ci.org/samvera/active_fedora)
|
|
5
|
+
[](https://coveralls.io/github/samvera/active_fedora?branch=master)
|
|
6
|
+
|
|
7
|
+
Docs: [](./CONTRIBUTING.md)
|
|
8
|
+
[](./LICENSE)
|
|
9
|
+
|
|
10
|
+
Jump in: [](http://slack.samvera.org/)
|
|
11
|
+
|
|
12
|
+
# What is ActiveFedora?
|
|
8
13
|
|
|
9
14
|
ActiveFedora is a Ruby gem for creating and
|
|
10
15
|
managing objects in the Fedora Repository Architecture
|
|
11
16
|
([http://fedora-commons.org](http://fedora-commons.org)). ActiveFedora
|
|
12
17
|
is loosely based on “ActiveRecord” in Rails. Version 9.0+ works with Fedora 4 and prior versions work on Fedora 3. Version 9.2+ works with Solr 4.10. Version 10.0+ works with Fedora >= 4.5.1.
|
|
13
18
|
|
|
14
|
-
|
|
15
|
-
|
|
19
|
+
## Product Owner & Maintenance
|
|
20
|
+
ActiveFedora is a Core Component of the Samvera community. The documentation for
|
|
21
|
+
what this means can be found
|
|
22
|
+
[here](http://samvera.github.io/core_components.html#requirements-for-a-core-component).
|
|
16
23
|
|
|
17
|
-
|
|
18
|
-
[http://groups.google.com/group/samvera-tech](http://groups.google.com/group/samvera-tech)
|
|
19
|
-
- Developers hang out on [slack.samvera.org](http://slack.samvera.org/)
|
|
24
|
+
### Product Owner
|
|
20
25
|
|
|
21
|
-
|
|
22
|
-
------------
|
|
26
|
+
[no-reply](https://github.com/no-reply)
|
|
23
27
|
|
|
24
|
-
|
|
28
|
+
# Help
|
|
25
29
|
|
|
26
|
-
|
|
27
|
-
gem install active-fedora
|
|
28
|
-
```
|
|
30
|
+
The Samvera community is here to help. Please see our [support guide](./SUPPORT.md).
|
|
29
31
|
|
|
30
|
-
Getting Started
|
|
31
|
-
---------------
|
|
32
|
+
# Getting Started
|
|
32
33
|
|
|
33
34
|
The [Dive into Hydra](https://github.com/samvera/hydra/wiki/Dive-into-Hydra)
|
|
34
35
|
gives you a brief tour through ActiveFedora’s features on the command line.
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
## Prerequisites
|
|
38
|
+
|
|
39
|
+
- A Fedora Commons Repository installation (configured by URL in fedora.yml)
|
|
40
|
+
- A Solr index (configured by URL in solr.yml)
|
|
41
|
+
- A JDK8+ installation (if running the test suite)
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
The gem is hosted on rubygems.
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
gem install active-fedora
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Generators
|
|
38
52
|
|
|
39
53
|
You can generate a model inheriting from ActiveFedora::Base.
|
|
40
54
|
|
|
@@ -42,8 +56,7 @@ You can generate a model inheriting from ActiveFedora::Base.
|
|
|
42
56
|
rails generate active_fedora:model Book
|
|
43
57
|
```
|
|
44
58
|
|
|
45
|
-
Testing (this Gem)
|
|
46
|
-
------------------
|
|
59
|
+
## Testing (this Gem)
|
|
47
60
|
|
|
48
61
|
In order to run the RSpec tests, you need to have a copy of the
|
|
49
62
|
ActiveFedora source code, and then run bundle install in the source
|
|
@@ -88,11 +101,9 @@ is installed, run:
|
|
|
88
101
|
rake spec
|
|
89
102
|
```
|
|
90
103
|
|
|
91
|
-
|
|
92
|
-
----------------
|
|
104
|
+
# Acknowledgments
|
|
93
105
|
|
|
94
|
-
|
|
106
|
+
This software has been developed by and is brought to you by the Samvera community. Learn more at the
|
|
107
|
+
[Samvera website](http://samvera.org/).
|
|
95
108
|
|
|
96
|
-
|
|
97
|
-
Justin Coyne, McClain Looney & Eddie Shin
|
|
98
|
-
([MediaShelf](http://yourmediashelf.com)), Rick Johnson (Notre Dame)
|
|
109
|
+

|
data/SUPPORT.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
If you would like to report an issue, first search [the list of issues](https://github.com/samvera/active_fedora/issues/) to see if someone else has already reported it, and then feel free to [create a new issue](https://github.com/samvera/active_fedora/issues/new).
|
|
2
|
+
|
|
3
|
+
If you have questions or need help, please email [the Samvera community tech list](https://groups.google.com/forum/#!forum/samvera-tech) or stop by the #dev channel in [the Samvera community Slack team](https://wiki.duraspace.org/pages/viewpage.action?pageId=87460391#Getintouch!-Slack).
|
|
4
|
+
|
|
5
|
+
You can learn more about the various Samvera communication channels on the [Get in touch!](https://wiki.duraspace.org/pages/viewpage.action?pageId=87460391) wiki page.
|
data/active-fedora.gemspec
CHANGED
|
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
|
|
|
8
8
|
s.platform = Gem::Platform::RUBY
|
|
9
9
|
s.authors = ["Matt Zumwalt", "McClain Looney", "Justin Coyne"]
|
|
10
10
|
s.email = ["samvera-tech@googlegroups.com"]
|
|
11
|
-
s.homepage = %q{https://github.com/
|
|
11
|
+
s.homepage = %q{https://github.com/samvera/active_fedora}
|
|
12
12
|
s.summary = %q{A convenience libary for manipulating documents in the Fedora Repository.}
|
|
13
13
|
s.description = %q{ActiveFedora provides for creating and managing objects in the Fedora Repository Architecture.}
|
|
14
14
|
s.license = "Apache-2.0"
|
|
@@ -16,26 +16,26 @@ Gem::Specification.new do |s|
|
|
|
16
16
|
|
|
17
17
|
s.add_dependency 'rsolr', '>= 1.1.2', '< 3'
|
|
18
18
|
s.add_dependency 'solrizer', '>= 3.4', '< 5'
|
|
19
|
-
s.add_dependency "activesupport", '>= 4.2.4', '<
|
|
20
|
-
s.add_dependency "activemodel", '>= 4.2', '<
|
|
19
|
+
s.add_dependency "activesupport", '>= 4.2.4', '< 5.3'
|
|
20
|
+
s.add_dependency "activemodel", '>= 4.2.10', '< 5.3'
|
|
21
21
|
s.add_dependency "active-triples", '>= 0.11.0', '< 2.0.0'
|
|
22
22
|
s.add_dependency "deprecation"
|
|
23
|
-
s.add_dependency "ldp", '
|
|
23
|
+
s.add_dependency "ldp", '>= 0.7.0', '< 2'
|
|
24
24
|
s.add_dependency "ruby-progressbar", '~> 1.0'
|
|
25
|
-
s.add_dependency 'faraday', '~> 0.12
|
|
25
|
+
s.add_dependency 'faraday', '~> 0.12'
|
|
26
26
|
s.add_dependency 'faraday-encoding', '0.0.4'
|
|
27
27
|
|
|
28
28
|
s.add_development_dependency "rails"
|
|
29
29
|
s.add_development_dependency "rdoc"
|
|
30
30
|
s.add_development_dependency "yard"
|
|
31
31
|
s.add_development_dependency "rake"
|
|
32
|
-
s.add_development_dependency "solr_wrapper", "~>
|
|
32
|
+
s.add_development_dependency "solr_wrapper", "~> 2.0"
|
|
33
33
|
s.add_development_dependency 'fcrepo_wrapper', '~> 0.2'
|
|
34
34
|
s.add_development_dependency "rspec", "~> 3.5"
|
|
35
35
|
s.add_development_dependency "rspec-its"
|
|
36
36
|
s.add_development_dependency "equivalent-xml"
|
|
37
37
|
s.add_development_dependency "simplecov", '~> 0.8'
|
|
38
|
-
s.add_development_dependency "rubocop", '~> 0.
|
|
38
|
+
s.add_development_dependency "rubocop", '~> 0.56.0'
|
|
39
39
|
s.add_development_dependency "rubocop-rspec", '~> 1.12.0'
|
|
40
40
|
|
|
41
41
|
s.files = `git ls-files`.split("\n")
|
|
@@ -15,7 +15,7 @@ module ActiveFedora
|
|
|
15
15
|
# Overriding so that we don't track previously_changed, which was
|
|
16
16
|
# rather expensive.
|
|
17
17
|
def clear_changed_attributes
|
|
18
|
-
|
|
18
|
+
clear_changes_information
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def changed?
|
|
@@ -36,7 +36,7 @@ module ActiveFedora
|
|
|
36
36
|
# Serializing head/tail/nodes slows things down CONSIDERABLY, and is not
|
|
37
37
|
# useful.
|
|
38
38
|
# @note This method is used by ActiveFedora::Base upstream for indexing,
|
|
39
|
-
# at https://github.com/
|
|
39
|
+
# at https://github.com/samvera/active_fedora/blob/master/lib/active_fedora/indexing_service.rb.
|
|
40
40
|
def serializable_hash(_options = nil)
|
|
41
41
|
{}
|
|
42
42
|
end
|
|
@@ -80,6 +80,7 @@ module ActiveFedora
|
|
|
80
80
|
# Set node subjects to a term in AF JUST so that AF will persist the
|
|
81
81
|
# sub-graphs.
|
|
82
82
|
# TODO: Find a way to fix this.
|
|
83
|
+
# See https://github.com/samvera/active_fedora/issues/1337
|
|
83
84
|
resource.set_value(:nodes, [])
|
|
84
85
|
self.nodes += graph.subjects.to_a
|
|
85
86
|
ordered_self.changes_committed!
|
|
@@ -26,6 +26,7 @@ module ActiveFedora::Associations::Builder
|
|
|
26
26
|
full_callback_name = "#{callback_name}_for_#{name}"
|
|
27
27
|
|
|
28
28
|
# TODO : why do i need method_defined? I think its because of the inheritance chain
|
|
29
|
+
# See https://github.com/samvera/active_fedora/issues/1333
|
|
29
30
|
model.class_attribute full_callback_name.to_sym unless model.method_defined?(full_callback_name)
|
|
30
31
|
|
|
31
32
|
callbacks = Array(options[callback_name.to_sym]).map do |callback|
|
|
@@ -43,6 +43,7 @@ module ActiveFedora
|
|
|
43
43
|
ids = Array(ids).reject(&:blank?)
|
|
44
44
|
replace(klass.find(ids)) # .index_by { |r| r.id }.values_at(*ids))
|
|
45
45
|
# TODO, like this when find() can return multiple records
|
|
46
|
+
# See https://github.com/samvera/active_fedora/issues/1340
|
|
46
47
|
# send("#{reflection.name}=", reflection.klass.find(ids))
|
|
47
48
|
# send("#{reflection.name}=", ids.collect { |id| reflection.klass.find(id)})
|
|
48
49
|
end
|
|
@@ -171,6 +172,7 @@ module ActiveFedora
|
|
|
171
172
|
# See delete for more info.
|
|
172
173
|
def delete_all
|
|
173
174
|
# TODO: load_target causes extra loads. Can't we just send delete requests?
|
|
175
|
+
# See https://github.com/samvera/active_fedora/issues/1341
|
|
174
176
|
delete(load_target).tap do
|
|
175
177
|
reset
|
|
176
178
|
loaded!
|
|
@@ -301,6 +303,7 @@ module ActiveFedora
|
|
|
301
303
|
def find_target
|
|
302
304
|
# TODO: don't reify, just store the solr results and lazily reify.
|
|
303
305
|
# For now, we set a hard limit of 1000 results.
|
|
306
|
+
# See https://github.com/samvera/active_fedora/issues/1358
|
|
304
307
|
records = ActiveFedora::QueryResultBuilder.reify_solr_results(load_from_solr(rows: SolrService::MAX_ROWS))
|
|
305
308
|
records.each { |record| set_inverse_instance(record) }
|
|
306
309
|
records
|
|
@@ -4,6 +4,7 @@ module ActiveFedora
|
|
|
4
4
|
class DirectlyContainsOneAssociation < SingularAssociation #:nodoc:
|
|
5
5
|
# Finds objects contained by the container predicate (either the configured has_member_relation or ldp:contains)
|
|
6
6
|
# TODO: Refactor this to use solr (for efficiency) instead of parsing the RDF graph. Requires indexing ActiveFedora::File objects into solr, including their RDF.type and, if possible, the id of their container
|
|
7
|
+
# See https://github.com/samvera/active_fedora/issues/1335
|
|
7
8
|
def find_target
|
|
8
9
|
# filtered_objects = container_association_proxy.to_a.select { |o| o.metadata_node.type.include?(options[:type]) }
|
|
9
10
|
query_node = if container_predicate = options[:has_member_relation]
|
|
@@ -2,6 +2,7 @@ module ActiveFedora
|
|
|
2
2
|
module Associations
|
|
3
3
|
# TODO: we may want to split this into two subclasses, one for has_member_relation
|
|
4
4
|
# and the other for is_member_of_relation
|
|
5
|
+
# See https://github.com/samvera/active_fedora/issues/1332
|
|
5
6
|
class IndirectlyContainsAssociation < ContainsAssociation #:nodoc:
|
|
6
7
|
# Add +records+ to this association. Returns +self+ so method calls may be chained.
|
|
7
8
|
# Since << flattens its argument list and inserts each record, +push+ and +concat+ behave identically.
|
|
@@ -40,6 +41,7 @@ module ActiveFedora
|
|
|
40
41
|
uris.map { |object_uri| klass.find(klass.uri_to_id(object_uri)) }
|
|
41
42
|
else # is_member_of_relation
|
|
42
43
|
# TODO this is a lot of reads. Avoid this path
|
|
44
|
+
# See https://github.com/samvera/active_fedora/issues/1345
|
|
43
45
|
container_predicate = ::RDF::Vocab::LDP.contains
|
|
44
46
|
proxy_uris = container.resource.query(predicate: container_predicate).map { |r| r.object.to_s }
|
|
45
47
|
proxy_uris.map { |uri| proxy_class.find(proxy_class.uri_to_id(uri))[options[:foreign_key]] }
|
|
@@ -33,6 +33,7 @@ module ActiveFedora
|
|
|
33
33
|
|
|
34
34
|
def find_target
|
|
35
35
|
# TODO: this forces a solr query, but I think it's likely we can just lookup from Fedora.
|
|
36
|
+
# See https://github.com/samvera/active_fedora/issues/1330
|
|
36
37
|
rec = scope.take
|
|
37
38
|
rec.tap { |record| set_inverse_instance(record) }
|
|
38
39
|
end
|
|
@@ -28,7 +28,7 @@ module ActiveFedora
|
|
|
28
28
|
|
|
29
29
|
def write_attribute(attribute_name, value)
|
|
30
30
|
if self.class.properties.key?(attribute_name)
|
|
31
|
-
|
|
31
|
+
attributes[attribute_name] = value
|
|
32
32
|
else
|
|
33
33
|
raise ActiveModel::MissingAttributeError, "can't write unknown attribute `#{attribute_name}'"
|
|
34
34
|
end
|
|
@@ -136,7 +136,7 @@ module ActiveFedora
|
|
|
136
136
|
# person.attribute_names
|
|
137
137
|
# # => ["id", "created_at", "updated_at", "name", "age"]
|
|
138
138
|
def attribute_names
|
|
139
|
-
@
|
|
139
|
+
@local_attributes.keys
|
|
140
140
|
end
|
|
141
141
|
|
|
142
142
|
# Returns a hash of all the attributes with their names as keys and the values of the attributes as values.
|
|
@@ -57,6 +57,7 @@ module ActiveFedora::Attributes
|
|
|
57
57
|
|
|
58
58
|
def build(&block)
|
|
59
59
|
# TODO: remove this block stuff
|
|
60
|
+
# See https://github.com/samvera/active_fedora/issues/1336
|
|
60
61
|
NodeConfig.new(name, options[:predicate], options.except(:predicate)) do |config|
|
|
61
62
|
config.with_index(&block) if block_given?
|
|
62
63
|
end
|
|
@@ -215,7 +215,8 @@ module ActiveFedora
|
|
|
215
215
|
:after_initialize, :after_find, :before_validation, :after_validation,
|
|
216
216
|
:before_save, :around_save, :after_save, :before_create, :around_create,
|
|
217
217
|
:after_create, :before_update, :around_update, :after_update,
|
|
218
|
-
:before_destroy, :around_destroy, :after_destroy
|
|
218
|
+
:before_destroy, :around_destroy, :after_destroy,
|
|
219
|
+
:before_update_index, :around_update_index, :after_update_index
|
|
219
220
|
].freeze
|
|
220
221
|
|
|
221
222
|
included do
|
|
@@ -223,13 +224,17 @@ module ActiveFedora
|
|
|
223
224
|
include ActiveModel::Validations::Callbacks
|
|
224
225
|
|
|
225
226
|
define_model_callbacks :initialize, :find, only: :after
|
|
226
|
-
define_model_callbacks :save, :create, :update, :destroy
|
|
227
|
+
define_model_callbacks :save, :create, :update, :destroy, :update_index
|
|
227
228
|
end
|
|
228
229
|
|
|
229
230
|
def destroy(*) #:nodoc:
|
|
230
231
|
_run_destroy_callbacks { super }
|
|
231
232
|
end
|
|
232
233
|
|
|
234
|
+
def update_index(*args)
|
|
235
|
+
_run_update_index_callbacks { super(*args) }
|
|
236
|
+
end
|
|
237
|
+
|
|
233
238
|
private
|
|
234
239
|
|
|
235
240
|
def create_or_update(*)
|
data/lib/active_fedora/fedora.rb
CHANGED
|
@@ -103,5 +103,13 @@ module ActiveFedora
|
|
|
103
103
|
ActiveFedora::Base.logger.warn "Fedora URL (#{host}) does not end with /rest. This could be a problem. Check your fedora.yml config"
|
|
104
104
|
end
|
|
105
105
|
end
|
|
106
|
+
|
|
107
|
+
def ntriples_connection
|
|
108
|
+
authorized_connection.tap { |conn| conn.headers['Accept'] = 'application/n-triples' }
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def build_ntriples_connection
|
|
112
|
+
ActiveFedora::InitializingConnection.new(ActiveFedora::CachingConnection.new(ntriples_connection, omit_ldpr_interaction_model: true), root_resource_path)
|
|
113
|
+
end
|
|
106
114
|
end
|
|
107
115
|
end
|
data/lib/active_fedora/file.rb
CHANGED
|
@@ -43,7 +43,7 @@ module ActiveFedora
|
|
|
43
43
|
raise "The first argument to #{self} must be a Hash, String or RDF::URI. You provided a #{identifier.class}"
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
@
|
|
46
|
+
@local_attributes = {}.with_indifferent_access
|
|
47
47
|
@readonly = false
|
|
48
48
|
yield self if block_given?
|
|
49
49
|
end
|
|
@@ -86,7 +86,7 @@ module ActiveFedora
|
|
|
86
86
|
@content = nil
|
|
87
87
|
@metadata = nil
|
|
88
88
|
@ds_content = nil
|
|
89
|
-
|
|
89
|
+
clear_attribute_changes(changes.keys)
|
|
90
90
|
end
|
|
91
91
|
|
|
92
92
|
def check_fixity
|
|
@@ -94,12 +94,12 @@ module ActiveFedora
|
|
|
94
94
|
end
|
|
95
95
|
|
|
96
96
|
def datastream_will_change!
|
|
97
|
-
attribute_will_change! :
|
|
97
|
+
attribute_will_change! :ldp_source
|
|
98
98
|
end
|
|
99
99
|
|
|
100
100
|
def attribute_will_change!(attr)
|
|
101
101
|
return super unless attr == 'content'
|
|
102
|
-
|
|
102
|
+
attributes_changed_by_setter[:content] = true
|
|
103
103
|
end
|
|
104
104
|
|
|
105
105
|
def remote_content
|
|
@@ -77,7 +77,7 @@ module ActiveFedora
|
|
|
77
77
|
protected
|
|
78
78
|
|
|
79
79
|
def rdf_resource
|
|
80
|
-
@rdf_resource ||= Ldp::Resource::RdfSource.new(ActiveFedora.fedora.
|
|
80
|
+
@rdf_resource ||= Ldp::Resource::RdfSource.new(ActiveFedora.fedora.build_ntriples_connection, uri)
|
|
81
81
|
end
|
|
82
82
|
|
|
83
83
|
def rdf_graph
|
|
@@ -22,6 +22,7 @@ module ActiveFedora
|
|
|
22
22
|
# @api
|
|
23
23
|
# Given a field name, index_type, etc., returns the corresponding Solr name.
|
|
24
24
|
# TODO field type is the input format, maybe we could just detect that?
|
|
25
|
+
# See https://github.com/samvera/active_fedora/issues/1338
|
|
25
26
|
# @param [String] field_name the ruby (term) name which will get a suffix appended to become a Solr field name
|
|
26
27
|
# @param opts - index_type is only needed if the FieldDescriptor requires it (e.g. :searcahble)
|
|
27
28
|
# @return [String] name of the solr field, based on the params
|
|
@@ -69,6 +70,7 @@ module ActiveFedora
|
|
|
69
70
|
|
|
70
71
|
# Is there a custom converter?
|
|
71
72
|
# TODO instead of a custom converter, look for input data type and output data type. Create a few methods that can do that cast.
|
|
73
|
+
# See https://github.com/samvera/active_fedora/issues/1339
|
|
72
74
|
|
|
73
75
|
value = if converter
|
|
74
76
|
if converter.arity == 1
|
|
@@ -45,12 +45,14 @@ module ActiveFedora
|
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
def self.config
|
|
48
|
+
# TODO: `:symbol' usage ought to be deprecated
|
|
49
|
+
# See https://github.com/samvera/active_fedora/issues/1334
|
|
48
50
|
@config ||= OpenStruct.new fields: [:type, :stored, :indexed, :multivalued],
|
|
49
51
|
suffix_delimiter: '_',
|
|
50
52
|
type_suffix: (lambda do |fields|
|
|
51
53
|
type = fields.first
|
|
52
54
|
case type
|
|
53
|
-
when :string, :symbol
|
|
55
|
+
when :string, :symbol
|
|
54
56
|
's'
|
|
55
57
|
when :text
|
|
56
58
|
't'
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# Similar to ActiveSupport.class_attribute but with a setter that doesn't use the #{name}= syntax
|
|
2
2
|
# This preserves backward compatibility with the API in ActiveTriples
|
|
3
|
+
require "active_support/core_ext/module/remove_method"
|
|
3
4
|
|
|
4
5
|
module ActiveFedora
|
|
5
6
|
module InheritableAccessors
|
|
@@ -131,6 +131,7 @@ module ActiveFedora
|
|
|
131
131
|
@resource = SolrBackedResource.new(self.class)
|
|
132
132
|
self.attributes = adapt_attributes(attrs)
|
|
133
133
|
# TODO: Should we clear the change tracking, or make this object Read-only?
|
|
134
|
+
# See https://github.com/samvera/active_fedora/issues/1342
|
|
134
135
|
|
|
135
136
|
yield self if block_given?
|
|
136
137
|
|
|
@@ -64,6 +64,7 @@ module ActiveFedora
|
|
|
64
64
|
reflection.autosave = true
|
|
65
65
|
define_autosave_association_callbacks(reflection)
|
|
66
66
|
## TODO this ought to work, but doesn't seem to do the class inheritance right
|
|
67
|
+
# See https://github.com/samvera/active_fedora/issues/1343
|
|
67
68
|
|
|
68
69
|
nested_attributes_options = self.nested_attributes_options.dup
|
|
69
70
|
nested_attributes_options[association_name.to_sym] = options
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module ActiveFedora
|
|
2
|
+
module Persistence
|
|
3
|
+
# An identifier service that doesn't mint IDs, so that the autocreated
|
|
4
|
+
# identifiers from Fedora will be used.
|
|
5
|
+
class NullIdentifierService
|
|
6
|
+
# Effectively a no-op
|
|
7
|
+
# @return [NilClass]
|
|
8
|
+
def mint; end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -2,6 +2,13 @@ module ActiveFedora
|
|
|
2
2
|
# = Active Fedora Persistence
|
|
3
3
|
module Persistence
|
|
4
4
|
extend ActiveSupport::Concern
|
|
5
|
+
extend ActiveSupport::Autoload
|
|
6
|
+
autoload :NullIdentifierService
|
|
7
|
+
|
|
8
|
+
included do
|
|
9
|
+
class_attribute :identifier_service_class
|
|
10
|
+
self.identifier_service_class = NullIdentifierService
|
|
11
|
+
end
|
|
5
12
|
|
|
6
13
|
def new_record?
|
|
7
14
|
return true if @ldp_source.subject.nil?
|
|
@@ -209,7 +216,13 @@ module ActiveFedora
|
|
|
209
216
|
end
|
|
210
217
|
|
|
211
218
|
# Override to tie in an ID minting service
|
|
212
|
-
def assign_id
|
|
219
|
+
def assign_id
|
|
220
|
+
identifier_service.mint
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
def identifier_service
|
|
224
|
+
@identifier_service ||= identifier_service_class.new
|
|
225
|
+
end
|
|
213
226
|
|
|
214
227
|
# This is only used when creating a new record. If the object doesn't have an id
|
|
215
228
|
# and assign_id can mint an id for the object, then assign it to the resource.
|
|
@@ -314,7 +314,7 @@ module ActiveFedora
|
|
|
314
314
|
def collect_join_chain
|
|
315
315
|
[self]
|
|
316
316
|
end
|
|
317
|
-
alias chain collect_join_chain #
|
|
317
|
+
alias chain collect_join_chain # TODO Remove alias, See https://github.com/samvera/active_fedora/issues/1347
|
|
318
318
|
|
|
319
319
|
def has_inverse?
|
|
320
320
|
inverse_name
|
|
@@ -13,7 +13,8 @@ module ActiveFedora
|
|
|
13
13
|
:keep_if, :pop, :shift, :delete_at, :select!
|
|
14
14
|
].to_set
|
|
15
15
|
|
|
16
|
-
delegate :length, :
|
|
16
|
+
delegate :length, :map, :to_ary, to: :to_a
|
|
17
|
+
delegate :any?, :all?, :collect, :include?, to: :each
|
|
17
18
|
|
|
18
19
|
protected
|
|
19
20
|
|
|
@@ -194,13 +194,17 @@ module ActiveFedora
|
|
|
194
194
|
ActiveFedora::Base
|
|
195
195
|
else
|
|
196
196
|
resource_class = ActiveFedora.model_mapper.classifier(resource).best_model
|
|
197
|
-
unless resource_class
|
|
197
|
+
unless equivalent_class?(resource_class)
|
|
198
198
|
raise ActiveFedora::ModelMismatch, "Expected #{@klass}. Got: #{resource_class}"
|
|
199
199
|
end
|
|
200
200
|
resource_class
|
|
201
201
|
end
|
|
202
202
|
end
|
|
203
203
|
|
|
204
|
+
def equivalent_class?(other_class)
|
|
205
|
+
other_class <= @klass
|
|
206
|
+
end
|
|
207
|
+
|
|
204
208
|
def find_with_ids(ids, cast)
|
|
205
209
|
expects_array = ids.first.is_a?(Array)
|
|
206
210
|
return ids.first if expects_array && ids.first.empty?
|
|
@@ -258,6 +262,7 @@ module ActiveFedora
|
|
|
258
262
|
def field_name_for(key)
|
|
259
263
|
if @klass.delegated_attributes.key?(key)
|
|
260
264
|
# TODO: Check to see if `key' is a possible solr field for this class, if it isn't try :searchable instead
|
|
265
|
+
# See https://github.com/samvera/active_fedora/issues/1344
|
|
261
266
|
ActiveFedora.index_field_mapper.solr_name(key, :stored_searchable, type: :string)
|
|
262
267
|
elsif key == :id
|
|
263
268
|
ActiveFedora.id_field
|
|
@@ -144,6 +144,20 @@ module ActiveFedora
|
|
|
144
144
|
@scope_for_create ||= where_values_hash.merge(create_with_value)
|
|
145
145
|
end
|
|
146
146
|
|
|
147
|
+
def each
|
|
148
|
+
if loaded?
|
|
149
|
+
@records.each { |item| yield item } if block_given?
|
|
150
|
+
@records.to_enum
|
|
151
|
+
else
|
|
152
|
+
find_each(where_values) { |item| yield item } if block_given?
|
|
153
|
+
enum_for(:find_each, where_values)
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def empty?
|
|
158
|
+
!any?
|
|
159
|
+
end
|
|
160
|
+
|
|
147
161
|
private
|
|
148
162
|
|
|
149
163
|
VALID_FIND_OPTIONS = [:order, :limit, :start, :conditions, :cast].freeze
|
|
@@ -92,5 +92,12 @@ module ActiveFedora
|
|
|
92
92
|
def perform_validations(options = {}) # :nodoc:
|
|
93
93
|
options[:validate] == false || valid?(options[:context])
|
|
94
94
|
end
|
|
95
|
+
|
|
96
|
+
private
|
|
97
|
+
|
|
98
|
+
# Overwrite run validations to include callbacks.
|
|
99
|
+
def run_validations!
|
|
100
|
+
_run_validation_callbacks { super }
|
|
101
|
+
end
|
|
95
102
|
end
|
|
96
103
|
end
|
|
@@ -15,6 +15,7 @@ module ActiveFedora
|
|
|
15
15
|
@file = file
|
|
16
16
|
super(file.uri, ldp_source.graph)
|
|
17
17
|
return unless self.class.type && !type.include?(self.class.type)
|
|
18
|
+
attributes_changed_by_setter[:type] = true if type.present?
|
|
18
19
|
# Workaround for https://github.com/ActiveTriples/ActiveTriples/issues/123
|
|
19
20
|
get_values(:type) << self.class.type
|
|
20
21
|
end
|
|
@@ -54,7 +55,7 @@ module ActiveFedora
|
|
|
54
55
|
|
|
55
56
|
def changed_attributes
|
|
56
57
|
super.tap do |changed|
|
|
57
|
-
changed
|
|
58
|
+
changed.merge('type' => true) if type.present? && new_record?
|
|
58
59
|
end
|
|
59
60
|
end
|
|
60
61
|
|
|
@@ -20,6 +20,7 @@ module ActiveFedora
|
|
|
20
20
|
|
|
21
21
|
def create_or_update(*)
|
|
22
22
|
return unless super && !new_record?
|
|
23
|
+
# TODOs captured as https://github.com/samvera/active_fedora/issues/1331
|
|
23
24
|
metadata_node.metadata_uri = described_by # TODO: only necessary if the URI was < > before
|
|
24
25
|
metadata_node.save # TODO if changed?
|
|
25
26
|
end
|
data/lib/active_fedora.rb
CHANGED
|
@@ -9,7 +9,7 @@ require 'active_support/core_ext/hash/except'
|
|
|
9
9
|
require 'active_triples'
|
|
10
10
|
|
|
11
11
|
# Monkey patching RDF::Literal::DateTime to support fractional seconds.
|
|
12
|
-
# See https://github.com/
|
|
12
|
+
# See https://github.com/samvera/active_fedora/issues/497
|
|
13
13
|
# Also monkey patches in a fix for timezones to be stored properly.
|
|
14
14
|
module RDF
|
|
15
15
|
class Literal
|