active-fedora 9.9.0 → 9.10.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 +20 -6
- data/.travis.yml +2 -6
- data/History.txt +146 -0
- data/active-fedora.gemspec +11 -8
- data/lib/active_fedora/associations/association.rb +44 -14
- data/lib/active_fedora/associations/association_scope.rb +6 -2
- data/lib/active_fedora/associations/basic_contains_association.rb +2 -3
- data/lib/active_fedora/associations/belongs_to_association.rb +23 -14
- data/lib/active_fedora/associations/builder/association.rb +95 -41
- data/lib/active_fedora/associations/builder/belongs_to.rb +30 -2
- data/lib/active_fedora/associations/builder/collection_association.rb +36 -4
- data/lib/active_fedora/associations/builder/contains.rb +10 -5
- data/lib/active_fedora/associations/builder/directly_contains.rb +6 -8
- data/lib/active_fedora/associations/builder/directly_contains_one.rb +27 -20
- data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +7 -3
- data/lib/active_fedora/associations/builder/has_many.rb +8 -45
- data/lib/active_fedora/associations/builder/indirectly_contains.rb +6 -8
- data/lib/active_fedora/associations/builder/property.rb +6 -12
- data/lib/active_fedora/associations/builder/singular_association.rb +3 -5
- data/lib/active_fedora/associations/builder/singular_property.rb +5 -4
- data/lib/active_fedora/associations/collection_association.rb +22 -26
- data/lib/active_fedora/associations/collection_proxy.rb +1 -1
- data/lib/active_fedora/associations/contained_finder.rb +1 -2
- data/lib/active_fedora/associations/directly_contains_one_association.rb +2 -3
- data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +1 -1
- data/lib/active_fedora/associations/has_many_association.rb +24 -5
- data/lib/active_fedora/associations/rdf.rb +1 -20
- data/lib/active_fedora/associations.rb +1 -1
- data/lib/active_fedora/attached_files.rb +2 -2
- data/lib/active_fedora/attribute_assignment.rb +55 -0
- data/lib/active_fedora/attribute_methods/read.rb +29 -44
- data/lib/active_fedora/attribute_methods/write.rb +16 -19
- data/lib/active_fedora/attribute_methods.rb +149 -29
- data/lib/active_fedora/attributes.rb +6 -18
- data/lib/active_fedora/autosave_association.rb +8 -12
- data/lib/active_fedora/base.rb +2 -2
- data/lib/active_fedora/caching_connection.rb +1 -1
- data/lib/active_fedora/callbacks.rb +9 -9
- data/lib/active_fedora/common.rb +67 -0
- data/lib/active_fedora/core.rb +11 -23
- data/lib/active_fedora/default_model_mapper.rb +24 -0
- data/lib/active_fedora/errors.rb +42 -0
- data/lib/active_fedora/fedora.rb +1 -1
- data/lib/active_fedora/file/attributes.rb +9 -10
- data/lib/active_fedora/file.rb +19 -56
- data/lib/active_fedora/file_persistence.rb +27 -0
- data/lib/active_fedora/indexing.rb +15 -9
- data/lib/active_fedora/indexing_service.rb +4 -4
- data/lib/active_fedora/inheritance.rb +34 -0
- data/lib/active_fedora/ldp_resource.rb +1 -0
- data/lib/active_fedora/model.rb +18 -16
- data/lib/active_fedora/model_classifier.rb +77 -0
- data/lib/active_fedora/nested_attributes.rb +145 -18
- data/lib/active_fedora/persistence.rb +23 -5
- data/lib/active_fedora/predicates.rb +3 -0
- data/lib/active_fedora/qualified_dublin_core_datastream.rb +1 -1
- data/lib/active_fedora/query_result_builder.rb +12 -28
- data/lib/active_fedora/querying.rb +1 -1
- data/lib/active_fedora/rdf/datastream_indexing.rb +1 -1
- data/lib/active_fedora/reflection.rb +212 -80
- data/lib/active_fedora/relation/calculations.rb +1 -5
- data/lib/active_fedora/relation/finder_methods.rb +39 -26
- data/lib/active_fedora/relation.rb +17 -0
- data/lib/active_fedora/scoping/default.rb +117 -0
- data/lib/active_fedora/scoping/named.rb +152 -4
- data/lib/active_fedora/scoping.rb +85 -2
- data/lib/active_fedora/simple_datastream.rb +1 -1
- data/lib/active_fedora/solr_hit.rb +71 -0
- data/lib/active_fedora/solr_instance_loader.rb +12 -36
- data/lib/active_fedora/solr_query_builder.rb +20 -25
- data/lib/active_fedora/solr_service.rb +24 -13
- data/lib/active_fedora/type/boolean.rb +23 -0
- data/lib/active_fedora/type/value.rb +118 -0
- data/lib/active_fedora/type.rb +8 -0
- data/lib/active_fedora/validations.rb +14 -5
- data/lib/active_fedora/version.rb +1 -1
- data/lib/active_fedora/versionable.rb +8 -7
- data/lib/active_fedora/with_metadata/metadata_node.rb +2 -1
- data/lib/active_fedora.rb +35 -15
- data/lib/generators/active_fedora/config/fedora/fedora_generator.rb +4 -0
- data/lib/generators/active_fedora/config/fedora/templates/.fcrepo_wrapper +3 -0
- data/lib/generators/active_fedora/config/solr/solr_generator.rb +4 -0
- data/lib/generators/active_fedora/config/solr/templates/.solr_wrapper +5 -0
- data/lib/generators/active_fedora/config/solr/templates/solr/config/solrconfig.xml +15 -0
- data/solr/config/solrconfig.xml +15 -0
- data/spec/config_helper.rb +0 -5
- data/spec/integration/associations_spec.rb +5 -5
- data/spec/integration/attached_files_spec.rb +4 -4
- data/spec/integration/base_spec.rb +4 -4
- data/spec/integration/bug_spec.rb +0 -1
- data/spec/integration/collection_association_spec.rb +34 -3
- data/spec/integration/file_spec.rb +2 -2
- data/spec/integration/full_featured_model_spec.rb +4 -4
- data/spec/integration/has_and_belongs_to_many_associations_spec.rb +1 -1
- data/spec/integration/has_many_associations_spec.rb +30 -1
- data/spec/integration/indirect_container_spec.rb +1 -1
- data/spec/integration/nested_attribute_spec.rb +6 -0
- data/spec/integration/ntriples_datastream_spec.rb +4 -4
- data/spec/integration/om_datastream_spec.rb +7 -7
- data/spec/integration/persistence_spec.rb +1 -1
- data/spec/integration/relation_delegation_spec.rb +1 -1
- data/spec/integration/scoped_query_spec.rb +13 -13
- data/spec/integration/solr_hit_spec.rb +52 -0
- data/spec/samples/hydra-mods_article_datastream.rb +2 -2
- data/spec/spec_helper.rb +5 -9
- data/spec/unit/active_fedora_spec.rb +0 -26
- data/spec/unit/attributes_spec.rb +13 -7
- data/spec/unit/base_spec.rb +20 -0
- data/spec/unit/builder/has_and_belongs_to_many_spec.rb +2 -3
- data/spec/unit/callback_spec.rb +3 -8
- data/spec/unit/collection_proxy_spec.rb +1 -1
- data/spec/unit/default_model_mapper_spec.rb +39 -0
- data/spec/unit/file_spec.rb +21 -2
- data/spec/unit/finder_methods_spec.rb +30 -6
- data/spec/unit/has_and_belongs_to_many_association_spec.rb +4 -4
- data/spec/unit/has_many_association_spec.rb +25 -3
- data/spec/unit/indexing_spec.rb +17 -3
- data/spec/unit/model_classifier_spec.rb +49 -0
- data/spec/unit/model_spec.rb +0 -9
- data/spec/unit/ntriples_datastream_spec.rb +16 -16
- data/spec/unit/om_datastream_spec.rb +7 -7
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +1 -1
- data/spec/unit/query_result_builder_spec.rb +4 -10
- data/spec/unit/query_spec.rb +28 -28
- data/spec/unit/rdf/indexing_service_spec.rb +16 -16
- data/spec/unit/reflection_spec.rb +2 -2
- data/spec/unit/scoping_spec.rb +67 -0
- data/spec/unit/simple_datastream_spec.rb +2 -2
- data/spec/unit/solr_config_options_spec.rb +29 -32
- data/spec/unit/solr_hit_spec.rb +58 -0
- data/spec/unit/solr_query_builder_spec.rb +9 -1
- data/spec/unit/solr_service_spec.rb +19 -3
- data/spec/unit/validations_spec.rb +1 -1
- metadata +82 -20
- data/spec/support/freeze_mocks.rb +0 -12
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
module ActiveFedora::File::Attributes
|
|
2
|
-
attr_writer :mime_type
|
|
3
|
-
|
|
4
2
|
def mime_type
|
|
5
|
-
|
|
3
|
+
fetch_mime_type
|
|
6
4
|
end
|
|
7
5
|
|
|
6
|
+
delegate :mime_type=, to: :metadata
|
|
7
|
+
|
|
8
8
|
def original_name
|
|
9
9
|
@original_name ||= fetch_original_name
|
|
10
10
|
end
|
|
@@ -21,11 +21,11 @@ module ActiveFedora::File::Attributes
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def persisted_size
|
|
24
|
-
ldp_source.head.
|
|
24
|
+
ldp_source.head.content_length unless new_record?
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
def dirty_size
|
|
28
|
-
content.size if
|
|
28
|
+
content.size if content_changed? && content.respond_to?(:size)
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
def size
|
|
@@ -60,7 +60,7 @@ module ActiveFedora::File::Attributes
|
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
def links
|
|
63
|
-
@links ||=
|
|
63
|
+
@links ||= ldp_source.head.links
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
def default_mime_type
|
|
@@ -68,13 +68,12 @@ module ActiveFedora::File::Attributes
|
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
def fetch_mime_type
|
|
71
|
-
return default_mime_type if new_record?
|
|
72
|
-
|
|
71
|
+
return default_mime_type if new_record? && metadata.mime_type.blank?
|
|
72
|
+
metadata.mime_type.first
|
|
73
73
|
end
|
|
74
74
|
|
|
75
75
|
def fetch_original_name
|
|
76
76
|
return if new_record?
|
|
77
|
-
|
|
78
|
-
URI.decode(m[:filename])
|
|
77
|
+
ldp_source.head.content_disposition_filename
|
|
79
78
|
end
|
|
80
79
|
end
|
data/lib/active_fedora/file.rb
CHANGED
|
@@ -12,13 +12,16 @@ module ActiveFedora
|
|
|
12
12
|
autoload :Streaming
|
|
13
13
|
autoload :Attributes
|
|
14
14
|
|
|
15
|
+
include Common
|
|
15
16
|
include ActiveFedora::File::Attributes
|
|
16
17
|
include ActiveFedora::File::Streaming
|
|
17
|
-
include ActiveFedora::
|
|
18
|
+
include ActiveFedora::FilePersistence
|
|
18
19
|
include ActiveFedora::Versionable
|
|
19
20
|
include ActiveModel::Dirty
|
|
21
|
+
include ActiveFedora::Callbacks
|
|
20
22
|
include AttributeMethods # allows 'content' to be tracked
|
|
21
23
|
include Identifiable
|
|
24
|
+
include Inheritance
|
|
22
25
|
include Scoping
|
|
23
26
|
|
|
24
27
|
generate_method 'content'
|
|
@@ -55,21 +58,15 @@ module ActiveFedora
|
|
|
55
58
|
end
|
|
56
59
|
|
|
57
60
|
@attributes = {}.with_indifferent_access
|
|
61
|
+
@readonly = false
|
|
58
62
|
yield self if block_given?
|
|
59
63
|
end
|
|
60
64
|
end
|
|
61
65
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
other.instance_of?(self.class) &&
|
|
67
|
-
uri.value.present? &&
|
|
68
|
-
other.uri == uri
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def ldp_source
|
|
72
|
-
@ldp_source || raise("NO source")
|
|
66
|
+
def save
|
|
67
|
+
super.tap do
|
|
68
|
+
metadata.save if metadata.changed?
|
|
69
|
+
end
|
|
73
70
|
end
|
|
74
71
|
|
|
75
72
|
def described_by
|
|
@@ -123,6 +120,7 @@ module ActiveFedora
|
|
|
123
120
|
def attribute_will_change!(attr)
|
|
124
121
|
if attr == 'content'
|
|
125
122
|
changed_attributes['content'] = true
|
|
123
|
+
elsif attr == 'type'
|
|
126
124
|
else
|
|
127
125
|
super
|
|
128
126
|
end
|
|
@@ -147,7 +145,15 @@ module ActiveFedora
|
|
|
147
145
|
end
|
|
148
146
|
|
|
149
147
|
def changed?
|
|
150
|
-
super || content_changed?
|
|
148
|
+
super || content_changed? || metadata_changed?
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def metadata_changed?
|
|
152
|
+
if new_record? || links['describedby'].blank?
|
|
153
|
+
false
|
|
154
|
+
else
|
|
155
|
+
metadata.changed?
|
|
156
|
+
end
|
|
151
157
|
end
|
|
152
158
|
|
|
153
159
|
def inspect
|
|
@@ -160,15 +166,6 @@ module ActiveFedora
|
|
|
160
166
|
false
|
|
161
167
|
end
|
|
162
168
|
|
|
163
|
-
# Freeze datastreams such that they can be loaded from Fedora, but can't be changed
|
|
164
|
-
def freeze
|
|
165
|
-
@frozen = true
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
def frozen?
|
|
169
|
-
@frozen.present?
|
|
170
|
-
end
|
|
171
|
-
|
|
172
169
|
# serializes any changed data into the content field
|
|
173
170
|
def serialize!
|
|
174
171
|
end
|
|
@@ -186,14 +183,6 @@ module ActiveFedora
|
|
|
186
183
|
local_or_remote_content(true)
|
|
187
184
|
end
|
|
188
185
|
|
|
189
|
-
def readonly?
|
|
190
|
-
false
|
|
191
|
-
end
|
|
192
|
-
|
|
193
|
-
def destroy(*)
|
|
194
|
-
run_callbacks(:destroy) { super }
|
|
195
|
-
end
|
|
196
|
-
|
|
197
186
|
def self.relation
|
|
198
187
|
FileRelation.new(self)
|
|
199
188
|
end
|
|
@@ -224,32 +213,6 @@ module ActiveFedora
|
|
|
224
213
|
headers
|
|
225
214
|
end
|
|
226
215
|
|
|
227
|
-
def create_record(_options = {})
|
|
228
|
-
run_callbacks(:create) do
|
|
229
|
-
run_callbacks(:save) do
|
|
230
|
-
return false if content.nil?
|
|
231
|
-
ldp_source.content = content
|
|
232
|
-
ldp_source.create do |req|
|
|
233
|
-
req.headers.merge!(ldp_headers)
|
|
234
|
-
end
|
|
235
|
-
refresh
|
|
236
|
-
end
|
|
237
|
-
end
|
|
238
|
-
end
|
|
239
|
-
|
|
240
|
-
def update_record(_options = {})
|
|
241
|
-
run_callbacks(:update) do
|
|
242
|
-
run_callbacks(:save) do
|
|
243
|
-
return true unless content_changed?
|
|
244
|
-
ldp_source.content = content
|
|
245
|
-
ldp_source.update do |req|
|
|
246
|
-
req.headers.merge!(ldp_headers)
|
|
247
|
-
end
|
|
248
|
-
refresh
|
|
249
|
-
end
|
|
250
|
-
end
|
|
251
|
-
end
|
|
252
|
-
|
|
253
216
|
def build_ldp_resource(id)
|
|
254
217
|
build_ldp_resource_via_uri self.class.id_to_uri(id)
|
|
255
218
|
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module ActiveFedora
|
|
2
|
+
module FilePersistence
|
|
3
|
+
extend ActiveSupport::Concern
|
|
4
|
+
|
|
5
|
+
include ActiveFedora::Persistence
|
|
6
|
+
|
|
7
|
+
private
|
|
8
|
+
|
|
9
|
+
def _create_record(_options = {})
|
|
10
|
+
return false if content.nil?
|
|
11
|
+
ldp_source.content = content
|
|
12
|
+
ldp_source.create do |req|
|
|
13
|
+
req.headers.merge!(ldp_headers)
|
|
14
|
+
end
|
|
15
|
+
refresh
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def _update_record(_options = {})
|
|
19
|
+
return true unless content_changed?
|
|
20
|
+
ldp_source.content = content
|
|
21
|
+
ldp_source.update do |req|
|
|
22
|
+
req.headers.merge!(ldp_headers)
|
|
23
|
+
end
|
|
24
|
+
refresh
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -15,6 +15,16 @@ module ActiveFedora
|
|
|
15
15
|
autoload :Map
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
+
included do
|
|
19
|
+
# Because the previous method of setting indexer was to override
|
|
20
|
+
# the class method, we must ensure that we aren't using the instance
|
|
21
|
+
# reader so that the old method still works.
|
|
22
|
+
class_attribute :indexer, instance_accessor: false
|
|
23
|
+
|
|
24
|
+
# This is the default indexer class to use for this model.
|
|
25
|
+
self.indexer = IndexingService
|
|
26
|
+
end
|
|
27
|
+
|
|
18
28
|
# Return a Hash representation of this object where keys in the hash are appropriate Solr field names.
|
|
19
29
|
# @param [Hash] _solr_doc (optional) Hash to insert the fields into
|
|
20
30
|
# @param [Hash] _opts (optional)
|
|
@@ -37,26 +47,26 @@ module ActiveFedora
|
|
|
37
47
|
# Determines whether a create operation causes a solr index of this object by default.
|
|
38
48
|
# Override this if you need different behavior.
|
|
39
49
|
def create_needs_index?
|
|
40
|
-
|
|
50
|
+
ActiveFedora.enable_solr_updates?
|
|
41
51
|
end
|
|
42
52
|
|
|
43
53
|
# Determines whether an update operation causes a solr index of this object by default.
|
|
44
54
|
# Override this if you need different behavior
|
|
45
55
|
def update_needs_index?
|
|
46
|
-
|
|
56
|
+
ActiveFedora.enable_solr_updates?
|
|
47
57
|
end
|
|
48
58
|
|
|
49
59
|
private
|
|
50
60
|
|
|
51
61
|
# index the record after it has been persisted to Fedora
|
|
52
|
-
def
|
|
62
|
+
def _create_record(options = {})
|
|
53
63
|
super
|
|
54
64
|
update_index if create_needs_index? && options.fetch(:update_index, true)
|
|
55
65
|
true
|
|
56
66
|
end
|
|
57
67
|
|
|
58
68
|
# index the record after it has been updated in Fedora
|
|
59
|
-
def
|
|
69
|
+
def _update_record(options = {})
|
|
60
70
|
super
|
|
61
71
|
update_index if update_needs_index? && options.fetch(:update_index, true)
|
|
62
72
|
true
|
|
@@ -72,10 +82,6 @@ module ActiveFedora
|
|
|
72
82
|
end
|
|
73
83
|
end
|
|
74
84
|
|
|
75
|
-
def indexer
|
|
76
|
-
IndexingService
|
|
77
|
-
end
|
|
78
|
-
|
|
79
85
|
def reindex_everything
|
|
80
86
|
descendants = descendant_uris(ActiveFedora::Base.id_to_uri(''))
|
|
81
87
|
descendants.shift # Discard the root uri
|
|
@@ -104,7 +110,7 @@ module ActiveFedora
|
|
|
104
110
|
resource = Ldp::Resource::RdfSource.new(ActiveFedora.fedora.connection, uri)
|
|
105
111
|
# GET could be slow if it's a big resource, we're using HEAD to avoid this problem,
|
|
106
112
|
# but this causes more requests to Fedora.
|
|
107
|
-
return [] unless
|
|
113
|
+
return [] unless resource.head.rdf_source?
|
|
108
114
|
immediate_descendant_uris = resource.graph.query(predicate: ::RDF::Vocab::LDP.contains).map { |descendant| descendant.object.to_s }
|
|
109
115
|
all_descendants_uris = [uri]
|
|
110
116
|
immediate_descendant_uris.each do |descendant_uri|
|
|
@@ -16,15 +16,15 @@ module ActiveFedora
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def self.profile_solr_name
|
|
19
|
-
@profile_solr_name ||= ActiveFedora
|
|
19
|
+
@profile_solr_name ||= ActiveFedora.index_field_mapper.solr_name("object_profile", :displayable)
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def self.create_time_solr_name
|
|
23
|
-
@create_time_solr_name ||= ActiveFedora
|
|
23
|
+
@create_time_solr_name ||= ActiveFedora.index_field_mapper.solr_name('system_create', :stored_sortable, type: :date)
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
def self.modified_time_solr_name
|
|
27
|
-
@modified_time_solr_name ||= ActiveFedora
|
|
27
|
+
@modified_time_solr_name ||= ActiveFedora.index_field_mapper.solr_name('system_modified', :stored_sortable, type: :date)
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def rdf_service
|
|
@@ -40,7 +40,7 @@ module ActiveFedora
|
|
|
40
40
|
Solrizer.set_field(solr_doc, 'system_modified', m_time, :stored_sortable)
|
|
41
41
|
Solrizer.set_field(solr_doc, 'active_fedora_model', object.class.inspect, :stored_sortable)
|
|
42
42
|
solr_doc[QueryResultBuilder::HAS_MODEL_SOLR_FIELD] = object.has_model
|
|
43
|
-
solr_doc[
|
|
43
|
+
solr_doc[ActiveFedora.id_field.to_sym] = object.id
|
|
44
44
|
solr_doc[self.class.profile_solr_name] = profile_service.new(object).export
|
|
45
45
|
object.declared_attached_files.each do |name, file|
|
|
46
46
|
solr_doc.merge! file.to_solr(solr_doc, name: name.to_s)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module ActiveFedora
|
|
2
|
+
module Inheritance
|
|
3
|
+
extend ActiveSupport::Concern
|
|
4
|
+
|
|
5
|
+
module ClassMethods
|
|
6
|
+
# Returns the class descending directly from ActiveFedora::Base, or
|
|
7
|
+
# an abstract class, if any, in the inheritance hierarchy.
|
|
8
|
+
#
|
|
9
|
+
# If A extends ActiveFedora::Base, A.base_class will return A. If B descends from A
|
|
10
|
+
# through some arbitrarily deep hierarchy, B.base_class will return A.
|
|
11
|
+
#
|
|
12
|
+
# If B < A and C < B and if A is an abstract_class then both B.base_class
|
|
13
|
+
# and C.base_class would return B as the answer since A is an abstract_class.
|
|
14
|
+
def base_class
|
|
15
|
+
return File if self == File || superclass == File
|
|
16
|
+
|
|
17
|
+
unless self <= Base
|
|
18
|
+
raise ActiveFedoraError, "#{name} doesn't belong in a hierarchy descending from ActiveFedora"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
if self == Base || superclass == Base || superclass.abstract_class?
|
|
22
|
+
self
|
|
23
|
+
else
|
|
24
|
+
superclass.base_class
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Abstract classes can't have default scopes.
|
|
29
|
+
def abstract_class?
|
|
30
|
+
self == Base
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -16,6 +16,7 @@ module ActiveFedora
|
|
|
16
16
|
# @param [RDF::Graph] original_graph The graph returned by the LDP server
|
|
17
17
|
# @return [RDF::Graph] A graph striped of any inlined resources present in the original
|
|
18
18
|
def build_graph(original_graph)
|
|
19
|
+
Deprecation.warn(ActiveFedora::LdpResource, '#build_graph is deprecated and will be removed in active-fedora 10.0')
|
|
19
20
|
inlined_resources = get.graph.query(predicate: Ldp.contains).map(&:object)
|
|
20
21
|
|
|
21
22
|
# ActiveFedora always wants to copy the resources to a new graph because it
|
data/lib/active_fedora/model.rb
CHANGED
|
@@ -1,29 +1,31 @@
|
|
|
1
|
-
SOLR_DOCUMENT_ID = "id".freeze unless defined?(SOLR_DOCUMENT_ID)
|
|
2
|
-
|
|
3
1
|
module ActiveFedora
|
|
4
2
|
# = ActiveFedora
|
|
5
3
|
# This module mixes various methods into the including class,
|
|
6
4
|
# much in the way ActiveRecord does.
|
|
7
5
|
module Model
|
|
6
|
+
# @deprecated
|
|
7
|
+
# Convenience method for getting class constant based on a string
|
|
8
|
+
# @example
|
|
9
|
+
# ActiveFedora::Model.class_from_string("Om")
|
|
10
|
+
# => Om
|
|
11
|
+
# ActiveFedora::Model.class_from_string("ActiveFedora::RdfNode::TermProxy")
|
|
12
|
+
# => ActiveFedora::RdfNode::TermProxy
|
|
13
|
+
# @example Search within ActiveFedora::RdfNode for a class called "TermProxy"
|
|
14
|
+
# ActiveFedora::Model.class_from_string("TermProxy", ActiveFedora::RdfNode)
|
|
15
|
+
# => ActiveFedora::RdfNode::TermProxy
|
|
16
|
+
def self.class_from_string(*args)
|
|
17
|
+
Deprecation.warn("ActiveFedora::Model.class_from_string has been deprecated and will be removed in ActiveFedora 10.0. Use ActiveFedora::ModelClassifier.class_from_string instead")
|
|
18
|
+
ActiveFedora::ModelClassifier.class_from_string(*args)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# @deprecated
|
|
8
22
|
# Takes a Fedora URI for a cModel, and returns a
|
|
9
23
|
# corresponding Model if available
|
|
10
24
|
# This method should reverse ClassMethods#to_class_uri
|
|
11
25
|
# @return [Class, False] the class of the model or false, if it does not exist
|
|
12
26
|
def self.from_class_uri(model_value)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return nil
|
|
16
|
-
end
|
|
17
|
-
ActiveFedora.class_from_string(model_value)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def self.class_exists?(class_name)
|
|
21
|
-
return false if class_name.empty?
|
|
22
|
-
klass = class_name.constantize
|
|
23
|
-
return klass.is_a?(Class)
|
|
24
|
-
rescue NameError
|
|
25
|
-
return false
|
|
27
|
+
Deprecation.warn("ActiveFedora::Model.from_class_uri has been deprecated and will be removed in ActiveFedora 10.0. Use ActiveFedora::ModelClassifier.from_class_uri instead")
|
|
28
|
+
ActiveFedora::ModelClassifier.new(Array(model_value)).best_model
|
|
26
29
|
end
|
|
27
|
-
private_class_method :class_exists?
|
|
28
30
|
end
|
|
29
31
|
end
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
module ActiveFedora
|
|
2
|
+
# Translate model names to classes
|
|
3
|
+
class ModelClassifier
|
|
4
|
+
# Convenience method for getting class constant based on a string
|
|
5
|
+
# @example
|
|
6
|
+
# ActiveFedora::Model.class_from_string("Om")
|
|
7
|
+
# => Om
|
|
8
|
+
# ActiveFedora::Model.class_from_string("ActiveFedora::RdfNode::TermProxy")
|
|
9
|
+
# => ActiveFedora::RdfNode::TermProxy
|
|
10
|
+
# @example Search within ActiveFedora::RdfNode for a class called "TermProxy"
|
|
11
|
+
# ActiveFedora::Model.class_from_string("TermProxy", ActiveFedora::RdfNode)
|
|
12
|
+
# => ActiveFedora::RdfNode::TermProxy
|
|
13
|
+
def self.class_from_string(full_class_name, container_class = Kernel)
|
|
14
|
+
container_class = container_class.name if container_class.is_a? Module
|
|
15
|
+
container_parts = container_class.split('::')
|
|
16
|
+
(container_parts + full_class_name.split('::')).flatten.inject(Kernel) do |mod, class_name|
|
|
17
|
+
if mod == Kernel
|
|
18
|
+
Object.const_get(class_name)
|
|
19
|
+
elsif mod.const_defined? class_name.to_sym
|
|
20
|
+
mod.const_get(class_name)
|
|
21
|
+
else
|
|
22
|
+
container_parts.pop
|
|
23
|
+
class_from_string(class_name, container_parts.join('::'))
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
attr_reader :class_names, :default
|
|
29
|
+
|
|
30
|
+
def initialize(class_names, default: ActiveFedora::Base)
|
|
31
|
+
@class_names = Array(class_names)
|
|
32
|
+
@default = default
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
##
|
|
36
|
+
# Convert all the provided class names to class instances
|
|
37
|
+
def models
|
|
38
|
+
class_names.map do |uri|
|
|
39
|
+
classify(uri)
|
|
40
|
+
end.compact
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
##
|
|
44
|
+
# Select the "best" class from the list of class names. We define
|
|
45
|
+
# the "best" class as:
|
|
46
|
+
# - a subclass of the given default, base class
|
|
47
|
+
# - preferring subclasses over the parent class
|
|
48
|
+
def best_model(opts = {})
|
|
49
|
+
best_model_match = opts.fetch(:default, default)
|
|
50
|
+
|
|
51
|
+
models.each do |model_value|
|
|
52
|
+
# If there is an inheritance structure, use the most specific case.
|
|
53
|
+
best_model_match = model_value if best_model_match.nil? || best_model_match > model_value
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
best_model_match
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
private
|
|
60
|
+
|
|
61
|
+
def classify(model_value)
|
|
62
|
+
unless class_exists?(model_value)
|
|
63
|
+
ActiveFedora::Base.logger.warn "'#{model_value}' is not a real class" if ActiveFedora::Base.logger
|
|
64
|
+
return nil
|
|
65
|
+
end
|
|
66
|
+
ActiveFedora::ModelClassifier.class_from_string(model_value)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def class_exists?(class_name)
|
|
70
|
+
return false if class_name.empty?
|
|
71
|
+
klass = class_name.constantize
|
|
72
|
+
return klass.is_a?(Class)
|
|
73
|
+
rescue NameError
|
|
74
|
+
return false
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|