Class: Bulkrax::ObjectFactory
Overview
rubocop:disable Metrics/ClassLength
Instance Attribute Summary
#attributes, #importer_run_id, #klass, #object, #related_parents_parsed_mapping, #replace_files, #source_identifier_value, #update_files, #user, #work_identifier, #work_identifier_search_field
Class Method Interface
collapse
-
.add_child_to_parent_work(parent:, child:) ⇒ Object
-
.add_resource_to_collection(collection:, resource:, user:) ⇒ Object
-
.clean! ⇒ Object
-
.export_properties ⇒ Object
-
.field_multi_value?(field:, model:) ⇒ Boolean
-
.field_supported?(field:, model:) ⇒ Boolean
-
.file_sets_for(resource:) ⇒ Object
-
.find(id) ⇒ Object
-
.find_or_create_default_admin_set ⇒ Object
-
.ordered_file_sets_for(object) ⇒ Object
-
.publish ⇒ Object
-
.query(q, **kwargs) ⇒ Object
rubocop:enable Metrics/ParameterLists.
-
.save!(resource:) ⇒ Object
-
.search_by_property(value:, klass:, field: nil, search_field: nil, name_field: nil, verify_property: false) ⇒ NilClass, ActiveFedora::Base
rubocop:disable Metrics/ParameterLists.
-
.solr_name(field_name) ⇒ Object
-
.update_index(resources: []) ⇒ Object
-
.update_index_for_file_sets_of(resource:) ⇒ Object
Instance Method Summary
collapse
add_user_to_collection_permissions, #add_user_to_collection_permissions, #base_permitted_attributes, #create, default_admin_set_id, default_admin_set_or_nil, #find, #find_or_create, find_or_nil, #initialize, #run, #run!, #search_by_identifier, #transformation_removes_blank_hash_values, #update
Methods included from Loggable
#log_created, #log_deleted_fs, #log_updated
#find_record
Class Method Details
.add_child_to_parent_work(parent:, child:) ⇒ Object
Note:
This does not save either object. We need to do that in another loop. Why? Because we might be adding many items to the parent.
14
15
16
17
18
|
# File 'app/factories/bulkrax/object_factory.rb', line 14
def self.add_child_to_parent_work(parent:, child:)
return true if parent.ordered_members.to_a.include?(child)
parent.ordered_members << child
end
|
.add_resource_to_collection(collection:, resource:, user:) ⇒ Object
20
21
22
23
24
25
|
# File 'app/factories/bulkrax/object_factory.rb', line 20
def self.add_resource_to_collection(collection:, resource:, user:)
collection.try(:reindex_extent=, Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX) if
defined?(Hyrax::Adapters::NestingIndexAdapter)
resource.member_of_collections << collection
save!(resource: resource, user: user)
end
|
.clean! ⇒ Object
129
130
131
132
133
|
# File 'app/factories/bulkrax/object_factory.rb', line 129
def self.clean!
super do
ActiveFedora::Cleaner.clean!
end
end
|
.export_properties ⇒ Object
33
34
35
36
37
|
# File 'app/factories/bulkrax/object_factory.rb', line 33
def self.export_properties
properties = Bulkrax.curation_concerns.map { |work| work.properties.keys }.flatten.uniq.sort
properties.reject { |prop| Bulkrax.reserved_properties.include?(prop) }
end
|
.field_multi_value?(field:, model:) ⇒ Boolean
39
40
41
42
43
44
|
# File 'app/factories/bulkrax/object_factory.rb', line 39
def self.field_multi_value?(field:, model:)
return false unless field_supported?(field: field, model: model)
return false unless model.singleton_methods.include?(:properties)
model&.properties&.[](field)&.[]("multiple")
end
|
.field_supported?(field:, model:) ⇒ Boolean
46
47
48
|
# File 'app/factories/bulkrax/object_factory.rb', line 46
def self.field_supported?(field:, model:)
model.method_defined?(field) && model.properties[field].present?
end
|
.file_sets_for(resource:) ⇒ Object
50
51
52
53
54
55
|
# File 'app/factories/bulkrax/object_factory.rb', line 50
def self.file_sets_for(resource:)
return [] if resource.blank?
return [resource] if resource.is_a?(Bulkrax.file_model_class)
resource.file_sets
end
|
.find(id) ⇒ Object
60
61
62
63
64
|
# File 'app/factories/bulkrax/object_factory.rb', line 60
def self.find(id)
ActiveFedora::Base.find(id)
rescue ActiveFedora::ObjectNotFoundError => e
raise ObjectFactoryInterface::ObjectNotFoundError, e.message
end
|
.find_or_create_default_admin_set ⇒ Object
66
67
68
69
|
# File 'app/factories/bulkrax/object_factory.rb', line 66
def self.find_or_create_default_admin_set
AdminSet.find_or_create_default_admin_set_id
end
|
.ordered_file_sets_for(object) ⇒ Object
143
144
145
|
# File 'app/factories/bulkrax/object_factory.rb', line 143
def self.ordered_file_sets_for(object)
object&.ordered_members.to_a.select(&:file_set?)
end
|
.publish ⇒ Object
71
72
73
|
# File 'app/factories/bulkrax/object_factory.rb', line 71
def self.publish(**)
return true
end
|
.query(q, **kwargs) ⇒ Object
rubocop:enable Metrics/ParameterLists
125
126
127
|
# File 'app/factories/bulkrax/object_factory.rb', line 125
def self.query(q, **kwargs)
ActiveFedora::SolrService.query(q, **kwargs)
end
|
.save!(resource:) ⇒ Object
147
148
149
|
# File 'app/factories/bulkrax/object_factory.rb', line 147
def self.save!(resource:, **)
resource.save!
end
|
.search_by_property(value:, klass:, field: nil, search_field: nil, name_field: nil, verify_property: false) ⇒ NilClass, ActiveFedora::Base
Note:
HEY WE’RE USING THIS FOR A WINGS CUSTOM QUERY. BE CAREFUL WITH REMOVING IT.
rubocop:disable Metrics/ParameterLists
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'app/factories/bulkrax/object_factory.rb', line 95
def self.search_by_property(value:, klass:, field: nil, search_field: nil, name_field: nil, verify_property: false)
return nil unless klass.respond_to?(:where)
return if value.blank?
return if verify_property && !klass.properties.keys.include?(search_field)
search_field ||= field
name_field ||= field
raise "You must provide either (search_field AND name_field) OR field parameters" if search_field.nil? || name_field.nil?
match = klass.where(search_field => value).detect do |m|
Array(m.send(name_field)).include?(value)
end
return match if match
end
|
.solr_name(field_name) ⇒ Object
135
136
137
138
139
140
141
|
# File 'app/factories/bulkrax/object_factory.rb', line 135
def self.solr_name(field_name)
if defined?(Hyrax)
Hyrax.index_field_mapper.solr_name(field_name)
else
ActiveFedora.index_field_mapper.solr_name(field_name)
end
end
|
.update_index(resources: []) ⇒ Object
151
152
153
|
# File 'app/factories/bulkrax/object_factory.rb', line 151
def self.update_index(resources: [])
Array(resources).each(&:update_index)
end
|
.update_index_for_file_sets_of(resource:) ⇒ Object
27
28
29
|
# File 'app/factories/bulkrax/object_factory.rb', line 27
def self.update_index_for_file_sets_of(resource:)
resource.file_sets.each(&:update_index) if resource.respond_to?(:file_sets)
end
|
Instance Method Details
#delete(_user) ⇒ Object
167
168
169
|
# File 'app/factories/bulkrax/object_factory.rb', line 167
def delete(_user)
find&.delete
end
|
#find_by_id ⇒ Object
157
158
159
160
161
162
163
164
165
|
# File 'app/factories/bulkrax/object_factory.rb', line 157
def find_by_id
return false if attributes[:id].blank?
method_name = klass.respond_to?(:exist?) ? :exist? : :exists?
klass.find(attributes[:id]) if klass.send(method_name, attributes[:id])
rescue Valkyrie::Persistence::ObjectNotFoundError
false
end
|