Module: Bulkrax::ImportBehavior
- Extended by:
- ActiveSupport::Concern
- Included in:
- Entry
- Defined in:
- app/models/concerns/bulkrax/import_behavior.rb
Overview
Import Behavior for Entry classes
Instance Method Summary collapse
- #add_admin_set_id ⇒ Object
- #add_collections ⇒ Object
- #add_rights_statement ⇒ Object
- #add_visibility ⇒ Object
- #build_for_importer ⇒ Object
- #build_metadata ⇒ Object
-
#collections_created? ⇒ Boolean
override this in a sub-class of Entry to ensure any collections have been created before building the work.
- #factory ⇒ Object
- #factory_class ⇒ Object
- #find_or_create_collection_ids ⇒ Object
-
#override_rights_statement ⇒ Object
try and deal with a couple possible states for this input field.
- #rights_statement ⇒ Object
Instance Method Details
#add_admin_set_id ⇒ Object
55 56 57 |
# File 'app/models/concerns/bulkrax/import_behavior.rb', line 55 def add_admin_set_id self.['admin_set_id'] = importerexporter.admin_set_id if self.['admin_set_id'].blank? end |
#add_collections ⇒ Object
59 60 61 62 63 |
# File 'app/models/concerns/bulkrax/import_behavior.rb', line 59 def add_collections return if find_or_create_collection_ids.blank? self.['collections'] = [] self.['collections'] += find_or_create_collection_ids.map { |c| { id: c } } end |
#add_rights_statement ⇒ Object
47 48 49 |
# File 'app/models/concerns/bulkrax/import_behavior.rb', line 47 def add_rights_statement self.['rights_statement'] = [parser.parser_fields['rights_statement']] if override_rights_statement || self.['rights_statement'].blank? end |
#add_visibility ⇒ Object
51 52 53 |
# File 'app/models/concerns/bulkrax/import_behavior.rb', line 51 def add_visibility self.['visibility'] = importerexporter.visibility if self.['visibility'].blank? end |
#build_for_importer ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/models/concerns/bulkrax/import_behavior.rb', line 8 def build_for_importer begin unless self.importerexporter.validate_only raise CollectionsCreatedError unless collections_created? @item = factory.run! end rescue RSolr::Error::Http, CollectionsCreatedError => e raise e rescue StandardError => e status_info(e) else status_info end return @item end |
#build_metadata ⇒ Object
34 35 36 |
# File 'app/models/concerns/bulkrax/import_behavior.rb', line 34 def raise StandardError, 'Not Implemented' end |
#collections_created? ⇒ Boolean
override this in a sub-class of Entry to ensure any collections have been created before building the work
30 31 32 |
# File 'app/models/concerns/bulkrax/import_behavior.rb', line 30 def collections_created? true end |
#factory ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'app/models/concerns/bulkrax/import_behavior.rb', line 65 def factory @factory ||= Bulkrax::ObjectFactory.new(attributes: self., source_identifier_value: identifier, work_identifier: parser.work_identifier, replace_files: replace_files, user: user, klass: factory_class, update_files: update_files) end |
#factory_class ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/models/concerns/bulkrax/import_behavior.rb', line 75 def factory_class fc = if self.&.[]('model').present? self.&.[]('model').is_a?(Array) ? self.&.[]('model')&.first : self.&.[]('model') elsif self.mapping&.[]('work_type').present? self.&.[]('work_type').is_a?(Array) ? self.&.[]('work_type')&.first : self.&.[]('work_type') else Bulkrax.default_work_type end fc.constantize rescue NameError nil rescue Bulkrax.default_work_type.constantize end |
#find_or_create_collection_ids ⇒ Object
25 26 27 |
# File 'app/models/concerns/bulkrax/import_behavior.rb', line 25 def find_or_create_collection_ids self.collection_ids end |
#override_rights_statement ⇒ Object
try and deal with a couple possible states for this input field
43 44 45 |
# File 'app/models/concerns/bulkrax/import_behavior.rb', line 43 def override_rights_statement %w[true 1].include?(parser.parser_fields['override_rights_statement'].to_s) end |
#rights_statement ⇒ Object
38 39 40 |
# File 'app/models/concerns/bulkrax/import_behavior.rb', line 38 def rights_statement parser.parser_fields['rights_statement'] end |