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, #child_jobs, #collections_created?, #factory, #factory_class, #find_collection_ids, #override_rights_statement, #parent_jobs, #rights_statement

Methods included from HasMatchers

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

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

.collection_fieldObject



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

def self.collection_field
  ActiveSupport::Deprecation.warn(
    'Creating Collections using the collection_field_mapping will no longer be supported as of Bulkrax version 3.0.' \
    ' Please configure Bulkrax to use related_parents_field_mapping and related_children_field_mapping instead.'
  )
  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)


61
62
63
# File 'app/models/bulkrax/entry.rb', line 61

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)


46
47
48
# File 'app/models/bulkrax/entry.rb', line 46

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)


53
54
55
# File 'app/models/bulkrax/entry.rb', line 53

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

Instance Method Details

#buildObject



81
82
83
84
85
86
87
# File 'app/models/bulkrax/entry.rb', line 81

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)


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

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

#find_collection(collection_identifier) ⇒ Object



108
109
110
111
112
113
# File 'app/models/bulkrax/entry.rb', line 108

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

#importer?Boolean

Returns:

  • (Boolean)


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

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

#last_runObject



104
105
106
# File 'app/models/bulkrax/entry.rb', line 104

def last_run
  self.importerexporter&.last_run
end

#source_identifierObject



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

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

#valid_system_id(model_class) ⇒ Object



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

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



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

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