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

Instance Method Details

#add_admin_set_idObject



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_collectionsObject



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_statementObject



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_visibilityObject



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_importerObject



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_metadataObject

Raises:

  • (StandardError)


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

Returns:

  • (Boolean)


30
31
32
# File 'app/models/concerns/bulkrax/import_behavior.rb', line 30

def collections_created?
  true
end

#factoryObject



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_classObject



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_idsObject



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_statementObject

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_statementObject



38
39
40
# File 'app/models/concerns/bulkrax/import_behavior.rb', line 38

def rights_statement
  parser.parser_fields['rights_statement']
end