Class: ImportArchivalObjects
- Inherits:
-
BulkImportParser
- Object
- BulkImportParser
- ImportArchivalObjects
- Defined in:
- backend/app/lib/bulk_import/import_archival_objects.rb
Constant Summary collapse
- START_MARKER =
/ArchivesSpace field code/.freeze
Constants included from JSONModel
JSONModel::REFERENCE_KEY_REGEX
Instance Method Summary collapse
-
#check_row ⇒ Object
look for all the required fields to make sure they are legit strip all the strings and turn publish and restrictions_flaginto true/false.
-
#initialize(input_file, content_type, current_user, opts, log_method = nil) ⇒ ImportArchivalObjects
constructor
A new instance of ImportArchivalObjects.
-
#initialize_handler_enums ⇒ Object
-
#log_row(row) ⇒ Object
-
#process_row(row_hash = nil) ⇒ Object
Methods inherited from BulkImportParser
Methods included from BulkImportMixins
#ao_save, #archival_object_from_ref, #archival_object_from_ref_or_uri, #archival_object_from_uri, #create_date, #created, #find_top_container, #handle_notes, #indicator_and_type_exist_for_resource?, #resolves, #resource_from_ref, #resource_match, #sub_container_from_barcode, #test_exceptions, #valid, #value_check
Methods included from CrudHelpers
#handle_create, #handle_delete, #handle_listing, #handle_raw_listing, #handle_unlimited_listing, #handle_update, scoped_dataset, with_record_conflict_reporting, #with_record_conflict_reporting
Methods included from URIResolver
add_resolve_wrapper, ensure_reference_is_valid, register_resolver, resolve_references, resolve_wrappers
Methods included from JSONModel
JSONModel, #JSONModel, add_error_handler, all, allow_unmapped_enum_value, backend_url, check_valid_refs, client_mode?, custom_validations, destroy_model, enum_default_value, enum_values, handle_error, init, load_schema, #models, models, parse_jsonmodel_ref, parse_reference, repository, repository_for, schema_src, set_publish_flags!, set_repository, strict_mode, strict_mode?, validate_schema, with_repository
Constructor Details
#initialize(input_file, content_type, current_user, opts, log_method = nil) ⇒ ImportArchivalObjects
Returns a new instance of ImportArchivalObjects.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'backend/app/lib/bulk_import/import_archival_objects.rb', line 6 def initialize(input_file, content_type, current_user, opts, log_method = nil) super(input_file, content_type, current_user, opts, log_method) @first_level_aos = [] @archival_levels = CvList.new("archival_record_level", @current_user) @container_types = CvList.new("container_type", @current_user) @date_types = CvList.new("date_type", @current_user) @date_labels = CvList.new("date_label", @current_user) @date_certainty = CvList.new("date_certainty", @current_user) @extent_types = CvList.new("extent_extent_type", @current_user) @extent_portions = CvList.new("extent_portion", @current_user) @instance_types ||= CvList.new("instance_instance_type", @current_user) @parents = ParentTracker.new @start_marker = START_MARKER end |
Instance Method Details
#check_row ⇒ Object
look for all the required fields to make sure they are legit strip all the strings and turn publish and restrictions_flaginto true/false
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 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 |
# File 'backend/app/lib/bulk_import/import_archival_objects.rb', line 31 def check_row err_arr = [] begin # we'll check hierarchical level first, in case there was a parent that didn't get created hier = @row_hash["hierarchy"] if !hier err_arr.push I18n.t("bulk_import.error.hier_miss") else hier = hier.to_i # we bail if the parent wasn't created! return I18n.t("bulk_import.error.hier_below_error_level") if (@error_level && hier > @error_level) err_arr.push I18n.t("bulk_import.error.hier_zero") if hier < 1 # going from a 1 to a 3, for example if (hier - 1) > @hier err_arr.push I18n.t("bulk_import.error.hier_wrong") if @hier == 0 if @validate_only err_arr.push I18n.t("bulk_import.error.hier_wrong_resource_validation") @hier = 1 else err_arr.push I18n.t("bulk_import.error.hier_wrong_resource") raise StopBulkImportException.new(err_arr.join(";")) end end end @hier = hier end missing_title = @row_hash["title"].nil? #date stuff: if already missing the title, we have to make sure the date label is valid missing_date = [@row_hash["begin"], @row_hash["end"], @row_hash["expression"]].reject(&:nil?).empty? if !missing_date begin label = @date_labels.value((@row_hash["dates_label"] || "creation")) rescue Exception => e err_arr.push I18n.t("bulk_import.error.invalid_date_label", :what => e.) if missing_title missing_date = true end end err_arr.push I18n.t("bulk_import.error.title_and_date") if (missing_title && missing_date) # tree hierachy level = value_check(@archival_levels, @row_hash["level"], err_arr) err_arr.push I18n.t("bulk_import.error.level") if level.nil? rescue StopBulkImportException => se raise se rescue Exception => e Log.error(["UNEXPLAINED EXCEPTION on check row", e., e.backtrace, @row_hash].pretty_inspect) end if err_arr.empty? || @validate_only @row_hash.each do |k, v| @row_hash[k] = v.strip if !v.nil? if k == "publish" || k == "restrictions_flag" @row_hash[k] = (v == "1") end end end err_arr.join("; ") end |
#initialize_handler_enums ⇒ Object
21 22 23 24 25 26 27 |
# File 'backend/app/lib/bulk_import/import_archival_objects.rb', line 21 def initialize_handler_enums @cih = ContainerInstanceHandler.new(@current_user, @validate_only) @doh = DigitalObjectHandler.new(@current_user, @validate_only) @sh = SubjectHandler.new(@current_user, @validate_only) @ah = AgentHandler.new(@current_user, @validate_only) @lh = LangHandler.new(@current_user) # doesn't need validation end |
#log_row(row) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'backend/app/lib/bulk_import/import_archival_objects.rb', line 139 def log_row(row) create_key = @validate_only ? "bulk_import.log_created_be" : "bulk_import.log_created" not_create_key = @validate_only ? "bulk_import.error.no_ao_be" : "bulk_import.error.no_ao" obj_key = @validate_only ? "bulk_import.log_obj_be" : "bulk_import.log_obj" if row.archival_object_id.nil? @log_method.call(I18n.t("bulk_import.log_error", :row => row.row, :what => I18n.t(not_create_key))) else log_obj = I18n.t(obj_key, :what => I18n.t("bulk_import.ao"), :nm => row.archival_object_display, :id => row.archival_object_id, :ref_id => row.ref_id) @log_method.call(I18n.t(create_key, :row => row.row, :what => log_obj)) end unless row.info.empty? row.info.each do |info| @log_method.call(I18n.t("bulk_import.log_info", :row => row.row, :what => info)) end end unless row.errors.empty? row.errors.each do |err| @log_method.call(I18n.t("bulk_import.log_error", :row => row.row, :what => err)) end end end |
#process_row(row_hash = nil) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'backend/app/lib/bulk_import/import_archival_objects.rb', line 89 def process_row(row_hash = nil) ao = nil ret_str = "" begin resource_match(@resource, @row_hash["ead"], @row_hash["res_uri"]) rescue Exception => e ret_str = e. end # mismatch of resource stops all other processing if ret_str.empty? ret_str = check_row end if !ret_str.empty? if @validate_only @report.add_errors(ret_str) else raise BulkImportException.new(I18n.t("bulk_import.row_error", :row => @counter, :errs => ret_str)) end end parent_uri = @parents.parent_for(@row_hash["hierarchy"].to_i) begin ao = create_archival_object(parent_uri) ao = ao_save(ao) rescue JSONModel::ValidationException => ve # ao won't have been created msg = I18n.t("bulk_import.error.second_save_error", :what => ve.errors, :title => ao.title, :pos => ao.position) @report.add_errors(msg) rescue Exception => e Log.error("UNEXPECTED ON SECOND SAVE#{e.message}") Log.error(e.backtrace.pretty_inspect) Log.error(ASUtils.jsonmodels_to_hashes(ao).pretty_inspect) raise BulkImportException.new(e.) end if !ao.nil? fail_test = (ao.title.nil? && ao.dates.empty?) || ao.level.nil? ao.uri = nil if fail_test @report.add_archival_object(ao) if !ao.nil? end @parents.set_uri(@hier, ao.uri) @created_refs << ao.uri if ao.uri && !@validate_only if @hier == 1 @first_level_aos.push ao.uri if @first_one && @start_position @need_to_move = (ao.position - @start_position) > 1 if !@validate_only @first_one = false end end end |