Class: BulkArchivalObjectUpdater
- Inherits:
-
Object
- Object
- BulkArchivalObjectUpdater
- Defined in:
- backend/app/lib/bulk_archival_object_updater.rb
Defined Under Namespace
Classes: AccessionCandidate, BulkUpdateFailed, DigitalObjectCandidate, Row, TopContainerCandidate
Constant Summary collapse
- BATCH_SIZE =
128
- SUBRECORD_DEFAULTS =
{ 'dates' => { 'label' => 'creation', }, 'instance' => { 'jsonmodel_type' => 'instance', 'sub_container' => { 'jsonmodel_type' => 'sub_container', 'top_container' => {'ref' => nil}, } }, 'note_multipart' => { 'jsonmodel_type' => 'note_multipart', 'subnotes' => [], }, 'note_singlepart' => { 'jsonmodel_type' => 'note_singlepart', 'content' => [], }, }
- INSTANCE_FIELD_MAPPINGS =
[ ['instance_type', 'instance_type'], ]
- SUB_CONTAINER_FIELD_MAPPINGS =
[ ['type_2', 'sub_container_type_2'], ['indicator_2', 'sub_container_indicator_2'], ['barcode_2', 'sub_container_barcode_2'], ['type_3', 'sub_container_type_3'], ['indicator_3', 'sub_container_indicator_3'] ]
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#info_messages ⇒ Object
readonly
Returns the value of attribute info_messages.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
-
#updated_uris ⇒ Object
readonly
Returns the value of attribute updated_uris.
Instance Method Summary collapse
-
#apply_deletes? ⇒ Boolean
-
#create_missing_top_containers? ⇒ Boolean
-
#initialize(filename, parameters) ⇒ BulkArchivalObjectUpdater
constructor
A new instance of BulkArchivalObjectUpdater.
-
#run ⇒ Object
Constructor Details
#initialize(filename, parameters) ⇒ BulkArchivalObjectUpdater
Returns a new instance of BulkArchivalObjectUpdater.
39 40 41 42 43 44 45 |
# File 'backend/app/lib/bulk_archival_object_updater.rb', line 39 def initialize(filename, parameters) @filename = filename @parameters = parameters @errors = [] = [] @updated_uris = [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors
2 3 4 |
# File 'backend/app/lib/bulk_archival_object_updater.rb', line 2 def errors @errors end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename
2 3 4 |
# File 'backend/app/lib/bulk_archival_object_updater.rb', line 2 def filename @filename end |
#info_messages ⇒ Object (readonly)
Returns the value of attribute info_messages
2 3 4 |
# File 'backend/app/lib/bulk_archival_object_updater.rb', line 2 def end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters
2 3 4 |
# File 'backend/app/lib/bulk_archival_object_updater.rb', line 2 def parameters @parameters end |
#updated_uris ⇒ Object (readonly)
Returns the value of attribute updated_uris
2 3 4 |
# File 'backend/app/lib/bulk_archival_object_updater.rb', line 2 def updated_uris @updated_uris end |
Instance Method Details
#apply_deletes? ⇒ Boolean
94 95 96 |
# File 'backend/app/lib/bulk_archival_object_updater.rb', line 94 def apply_deletes? AppConfig.has_key?(:bulk_archival_object_updater_apply_deletes) && AppConfig[:bulk_archival_object_updater_apply_deletes] == true end |
#create_missing_top_containers? ⇒ Boolean
98 99 100 101 102 103 104 105 106 |
# File 'backend/app/lib/bulk_archival_object_updater.rb', line 98 def create_missing_top_containers? if parameters.has_key?(:create_missing_top_containers) parameters[:create_missing_top_containers] elsif AppConfig.has_key?(:bulk_archival_object_updater_create_missing_top_containers) AppConfig[:bulk_archival_object_updater_create_missing_top_containers] else false end end |
#run ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'backend/app/lib/bulk_archival_object_updater.rb', line 47 def run check_sheet(filename) column_by_path = extract_columns(filename) subrecord_columns = find_subrecord_columns(column_by_path) DB.open(true) do |db| resource_id = resource_ids_in_play(filename).fetch(0) @top_containers_in_resource = subrecord_columns[:top_container] ? extract_top_containers_for_resource(db, resource_id) : {} if SpreadsheetBuilder. @accessions_in_sheet = subrecord_columns[:related_accession] ? extract_accessions_from_sheet(db, filename, subrecord_columns[:related_accession]) : {} end if create_missing_top_containers? && subrecord_columns[:top_container] top_containers_in_sheet = extract_top_containers_from_sheet(filename, subrecord_columns[:top_container]) create_missing_top_containers(top_containers_in_sheet) end if subrecord_columns[:digital_object] digital_objects_in_sheet = extract_digital_objects_from_sheet(filename, subrecord_columns[:digital_object]) @digital_object_id_to_uri_map = apply_digital_objects_changes(digital_objects_in_sheet, db) end batch_rows(filename) do |batch| to_process = batch.map {|row| [Integer(row.fetch('id')), row]}.to_h ao_objs = ArchivalObject.filter(:id => to_process.keys).all ao_jsons = ArchivalObject.sequel_to_jsonmodel(ao_objs) ao_objs.zip(ao_jsons).each do |ao, ao_json| process_row(to_process.fetch(ao.id), ao, ao_json, column_by_path, subrecord_columns) end end if errors.length > 0 raise BulkUpdateFailed.new(errors) end end { updated_uris: updated_uris } end |