Class: Bulkrax::Entry

Inherits:
ApplicationRecord show all
Includes:
ExportBehavior, HasLocalProcessing, HasMatchers, ImportBehavior, StatusInfo
Defined in:
app/models/bulkrax/entry.rb

Direct Known Subclasses

CsvEntry, OaiEntry, RdfEntry, XmlEntry

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HasLocalProcessing

#add_local

Methods included from StatusInfo

#current_status, #failed?, #last_error, #set_status_info, #skipped?, #status, #status_at, #succeeded?

Methods included from ExportBehavior

#build_export_metadata, #build_for_exporter, #filename, #hyrax_record

Methods included from ImportBehavior

#active_id_for_authority?, #add_admin_set_id, #add_collections, #add_rights_statement, #add_user_to_permission_templates!, #add_visibility, #build_for_importer, #build_metadata, #child_jobs, #collections_created?, #factory, #factory_class, #find_collection_ids, #override_rights_statement, #parent_jobs, #rights_statement, #sanitize_controlled_uri_value, #sanitize_controlled_uri_values!, #validate_value

Methods included from HasMatchers

#add_metadata, #excluded?, #field_supported?, #field_to, #fields_that_are_always_multiple, #fields_that_are_always_singular, #get_object_name, #matched_metadata, #multiple?, #multiple_metadata, #schema_form_definitions, #set_parsed_data, #set_parsed_object_data, #single_metadata, #supported_bulkrax_fields

Instance Attribute Details

#all_attrsObject

Returns the value of attribute all_attrs.



27
28
29
# File 'app/models/bulkrax/entry.rb', line 27

def all_attrs
  @all_attrs
end

Class Method Details

.data_for_entry(_data, _source_id, _parser) ⇒ Object

Returns formatted data from the given file for a single Entry

Parameters:

  • data
    • the data from the metadata file

  • path
    • the path to the metadata file (used by some entries to get the file_paths for import)

Returns:

  • Hash containing the data (the entry build_metadata method will know what to expect in the hash)

Raises:

  • (StandardError)


65
66
67
# File 'app/models/bulkrax/entry.rb', line 65

def self.data_for_entry(_data, _source_id, _parser)
  raise StandardError, 'Not Implemented'
end

.fields_from_data(_data) ⇒ Object

Retrieve fields from the file

Parameters:

  • data
    • the source data

Returns:

  • Array

Raises:

  • (StandardError)


50
51
52
# File 'app/models/bulkrax/entry.rb', line 50

def self.fields_from_data(_data)
  raise StandardError, 'Not Implemented'
end

.parent_field(parser) ⇒ Object



86
87
88
# File 'app/models/bulkrax/entry.rb', line 86

def self.parent_field(parser)
  parser.related_parents_parsed_mapping
end

.read_data(_path) ⇒ Object

Read the data from the supplied path

Parameters:

  • path
    • path to the data file

Returns:

  • the data from the file

Raises:

  • (StandardError)


57
58
59
# File 'app/models/bulkrax/entry.rb', line 57

def self.read_data(_path)
  raise StandardError, 'Not Implemented'
end

Instance Method Details

#buildObject



90
91
92
93
94
95
96
# File 'app/models/bulkrax/entry.rb', line 90

def build
  return if type.nil?
  self.save if self.new_record? # must be saved for statuses

  return build_for_importer if importer?
  return build_for_exporter if exporter?
end

#exporter?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'app/models/bulkrax/entry.rb', line 102

def exporter?
  self.importerexporter_type == 'Bulkrax::Exporter'
end

#fetch_field_mappingObject

Returns field_mapping hash based on whether or not generated metadata should be included



78
79
80
81
82
83
84
# File 'app/models/bulkrax/entry.rb', line 78

def fetch_field_mapping
  return self.mapping if importerexporter.

  self.mapping.each do |key, value|
    self.mapping.delete(key) if value[]
  end
end

#find_collection(collection_identifier) ⇒ Object



110
111
112
113
114
115
116
117
118
# File 'app/models/bulkrax/entry.rb', line 110

def find_collection(collection_identifier)
  Bulkrax.object_factory.search_by_property(
    klass: Bulkrax.collection_model_class,
    value: collection_identifier,
    search_field: work_identifier,
    name_field: work_identifier,
    verify_property: true
  )
end

#importer?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'app/models/bulkrax/entry.rb', line 98

def importer?
  self.importerexporter_type == 'Bulkrax::Importer'
end

#last_runObject



106
107
108
# File 'app/models/bulkrax/entry.rb', line 106

def last_run
  self.importerexporter&.last_run
end

#source_identifierObject



69
70
71
# File 'app/models/bulkrax/entry.rb', line 69

def source_identifier
  parser&.source_identifier&.to_s || 'source_identifier'
end

#work_identifierObject



73
74
75
# File 'app/models/bulkrax/entry.rb', line 73

def work_identifier
  parser&.work_identifier&.to_s || 'source'
end