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, #status, #status_at, #status_info, #succeeded?

Methods included from ExportBehavior

#build_export_metadata, #build_for_exporter, #filename, #hyrax_record, #write_files

Methods included from ImportBehavior

#add_admin_set_id, #add_collections, #add_rights_statement, #add_visibility, #build_for_importer, #build_metadata, #collections_created?, #factory, #factory_class, #find_or_create_collection_ids, #override_rights_statement, #rights_statement

Methods included from HasMatchers

#add_metadata, #excluded?, #field_supported?, #field_to, #get_object_name, #matched_metadata, #multiple?, #multiple_metadata, #set_parsed_data, #single_metadata

Instance Attribute Details

#all_attrsObject

Returns the value of attribute all_attrs.



24
25
26
# File 'app/models/bulkrax/entry.rb', line 24

def all_attrs
  @all_attrs
end

Class Method Details

.children_fieldObject



67
68
69
# File 'app/models/bulkrax/entry.rb', line 67

def self.children_field
  Bulkrax.parent_child_field_mapping[self.to_s]
end

.collection_fieldObject



63
64
65
# File 'app/models/bulkrax/entry.rb', line 63

def self.collection_field
  Bulkrax.collection_field_mapping[self.to_s]
end

.data_for_entry(_data, _source_id) ⇒ 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)


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

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

.fields_from_data(_data) ⇒ Object

Retrieve fields from the file

Parameters:

  • data
    • the source data

Returns:

  • Array

Raises:

  • (StandardError)


36
37
38
# File 'app/models/bulkrax/entry.rb', line 36

def self.fields_from_data(_data)
  raise StandardError, 'Not Implemented'
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)


43
44
45
# File 'app/models/bulkrax/entry.rb', line 43

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

Instance Method Details

#buildObject



71
72
73
74
75
76
77
# File 'app/models/bulkrax/entry.rb', line 71

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)


83
84
85
# File 'app/models/bulkrax/entry.rb', line 83

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

#find_collection(collection_identifier) ⇒ Object



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

def find_collection(collection_identifier)
  Collection.where(
    work_identifier => collection_identifier
  ).detect { |m| m.send(work_identifier).include?(collection_identifier) }
end

#importer?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'app/models/bulkrax/entry.rb', line 79

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

#last_runObject



94
95
96
# File 'app/models/bulkrax/entry.rb', line 94

def last_run
  self.importerexporter&.last_run
end

#source_identifierObject



55
56
57
# File 'app/models/bulkrax/entry.rb', line 55

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

#valid_system_id(model_class) ⇒ Object



87
88
89
90
91
92
# File 'app/models/bulkrax/entry.rb', line 87

def valid_system_id(model_class)
  return true if model_class.properties.keys.include?(work_identifier)
  raise(
    "#{model_class} does not implement the system_identifier_field: #{work_identifier}"
  )
end

#work_identifierObject



59
60
61
# File 'app/models/bulkrax/entry.rb', line 59

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