Class: Bulkrax::Exporter
Instance Method Summary
collapse
Methods included from StatusInfo
#current_status, #failed?, #last_error, #set_status_info, #status, #status_at, #succeeded?
#file?, #increment_counters, #key_without_numbers, #keys_without_numbers, #last_imported_at, #next_import_at, #parser, #parser_class, #zip?
Instance Method Details
#current_run ⇒ Object
105
106
107
108
|
# File 'app/models/bulkrax/exporter.rb', line 105
def current_run
total = self.limit || parser.total
@current_run ||= self.exporter_runs.create!(total_work_entries: total, enqueued_records: total)
end
|
#date_filter ⇒ Object
41
42
43
|
# File 'app/models/bulkrax/exporter.rb', line 41
def date_filter
self.start_date.present? || self.finish_date.present?
end
|
#export ⇒ Object
19
20
21
22
23
24
|
# File 'app/models/bulkrax/exporter.rb', line 19
def export
current_run && setup_export_path
send("create_from_#{self.export_from}")
rescue StandardError => e
set_status_info(e)
end
|
#export_from_list ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'app/models/bulkrax/exporter.rb', line 77
def export_from_list
if defined?(::Hyrax)
[
[I18n.t('bulkrax.exporter.labels.importer'), 'importer'],
[I18n.t('bulkrax.exporter.labels.collection'), 'collection'],
[I18n.t('bulkrax.exporter.labels.worktype'), 'worktype'],
[I18n.t('bulkrax.exporter.labels.all'), 'all']
]
else
[
[I18n.t('bulkrax.exporter.labels.importer'), 'importer'],
[I18n.t('bulkrax.exporter.labels.collection'), 'collection'],
[I18n.t('bulkrax.exporter.labels.all'), 'all']
]
end
end
|
#export_properties ⇒ Object
132
133
134
135
|
# File 'app/models/bulkrax/exporter.rb', line 132
def export_properties
properties = Bulkrax.curation_concerns.map { |work| work.properties.keys }.flatten.uniq.sort
properties.reject { |prop| Bulkrax.reserved_properties.include?(prop) }
end
|
#export_source_collection ⇒ Object
33
34
35
|
# File 'app/models/bulkrax/exporter.rb', line 33
def export_source_collection
self.export_source if self.export_from == 'collection'
end
|
#export_source_importer ⇒ Object
#export_source accessors Used in form to prevent it from getting confused as to which value to populate #export_source with. Also, used to display the correct selected value when rendering edit form.
29
30
31
|
# File 'app/models/bulkrax/exporter.rb', line 29
def export_source_importer
self.export_source if self.export_from == 'importer'
end
|
#export_source_worktype ⇒ Object
37
38
39
|
# File 'app/models/bulkrax/exporter.rb', line 37
def export_source_worktype
self.export_source if self.export_from == 'worktype'
end
|
#export_type_list ⇒ Object
94
95
96
97
98
99
|
# File 'app/models/bulkrax/exporter.rb', line 94
def export_type_list
[
[I18n.t('bulkrax.exporter.labels.metadata'), 'metadata'],
[I18n.t('bulkrax.exporter.labels.full'), 'full']
]
end
|
#exporter_export_path ⇒ Object
118
119
120
|
# File 'app/models/bulkrax/exporter.rb', line 118
def exporter_export_path
@exporter_export_path ||= File.join(parser.base_path('export'), self.id.to_s, self.exporter_runs.last.id.to_s)
end
|
#exporter_export_zip_files ⇒ Object
128
129
130
|
# File 'app/models/bulkrax/exporter.rb', line 128
def exporter_export_zip_files
@exporter_export_zip_files ||= Dir["#{exporter_export_zip_path}/**"].map { |zip| Array(zip.split('/').last) }
end
|
#exporter_export_zip_path ⇒ Object
122
123
124
125
126
|
# File 'app/models/bulkrax/exporter.rb', line 122
def exporter_export_zip_path
@exporter_export_zip_path ||= File.join(parser.base_path('export'), "export_#{self.id}_#{self.exporter_runs.last.id}")
rescue
@exporter_export_zip_path ||= File.join(parser.base_path('export'), "export_#{self.id}_0")
end
|
49
50
51
|
# File 'app/models/bulkrax/exporter.rb', line 49
def generated_metadata?
self.generated_metadata
end
|
#importers_list ⇒ Object
101
102
103
|
# File 'app/models/bulkrax/exporter.rb', line 101
def importers_list
Importer.all.map { |i| [i.name, i.id] }
end
|
#include_thumbnails? ⇒ Boolean
45
46
47
|
# File 'app/models/bulkrax/exporter.rb', line 45
def include_thumbnails?
self.include_thumbnails
end
|
#last_run ⇒ Object
110
111
112
|
# File 'app/models/bulkrax/exporter.rb', line 110
def last_run
@last_run ||= self.exporter_runs.last
end
|
#mapping ⇒ Object
If field_mapping is empty, setup a default based on the export_properties
67
68
69
70
71
72
73
74
75
|
# File 'app/models/bulkrax/exporter.rb', line 67
def mapping
@mapping ||= self.field_mapping ||
ActiveSupport::HashWithIndifferentAccess.new(
export_properties.map do |m|
Bulkrax.default_field_mapping.call(m)
end.inject(:merge)
) ||
[{}]
end
|
137
138
139
|
# File 'app/models/bulkrax/exporter.rb', line 137
def metadata_only?
export_type == 'metadata'
end
|
#setup_export_path ⇒ Object
114
115
116
|
# File 'app/models/bulkrax/exporter.rb', line 114
def setup_export_path
FileUtils.mkdir_p(exporter_export_path) unless File.exist?(exporter_export_path)
end
|
#sort_zip_files(zip_files) ⇒ Object
141
142
143
144
145
146
147
148
|
# File 'app/models/bulkrax/exporter.rb', line 141
def sort_zip_files(zip_files)
zip_files.sort_by do |item|
number = item.split('_').last.match(/\d+/)&.[](0) || 0.to_s
sort_number = number.rjust(4, "0")
sort_number
end
end
|
#work_visibility_list ⇒ Object
53
54
55
56
57
58
59
60
|
# File 'app/models/bulkrax/exporter.rb', line 53
def work_visibility_list
[
['Any', ''],
[I18n.t('hyrax.visibility.open.text'), Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC],
[I18n.t('hyrax.visibility.restricted.text'), Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE],
[I18n.t('hyrax.visibility.authenticated.text', institution: I18n.t('hyrax.institution_name')), Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED]
]
end
|
#workflow_status_list ⇒ Object
62
63
64
|
# File 'app/models/bulkrax/exporter.rb', line 62
def workflow_status_list
Sipity::WorkflowState.all.map { |s| [s.name&.titleize, s.name] }.uniq if defined?(::Hyrax)
end
|