Class: ImportDigitalObjects
- Inherits:
-
BulkImportParser
- Object
- BulkImportParser
- ImportDigitalObjects
- Defined in:
- backend/app/lib/bulk_import/import_digital_objects.rb
Constant Summary collapse
- START_MARKER =
/ArchivesSpace digital object import field codes/.freeze
Constants included from JSONModel
JSONModel::REFERENCE_KEY_REGEX
Instance Method Summary collapse
-
#check_row ⇒ Object
required fields for a digital object row: ead match, (ao_ref_id or ao_uri).
-
#create_instance(ao) ⇒ Object
-
#initialize(input_file, content_type, current_user, opts, log_method = nil) ⇒ ImportDigitalObjects
constructor
A new instance of ImportDigitalObjects.
-
#initialize_handler_enums ⇒ Object
-
#log_row(row) ⇒ Object
-
#process_row ⇒ Object
-
#verify_ao(ref_id, uri, errs) ⇒ Object
any problem here would result in the digital object not being created.
Methods inherited from BulkImportParser
#initialize_info, #record_uris, #run
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) ⇒ ImportDigitalObjects
Returns a new instance of ImportDigitalObjects.
6 7 8 9 10 11 12 |
# File 'backend/app/lib/bulk_import/import_digital_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) @find_uri = "/repositories/#{@opts[:repo_id]}/find_by_id/archival_objects" @resource_ref = "/repositories/#{@opts[:repo_id]}/resources/#{@opts[:id]}" @repo_id = @opts[:repo_id] @start_marker = START_MARKER # replace down stream end |
Instance Method Details
#check_row ⇒ Object
required fields for a digital object row: ead match, (ao_ref_id or ao_uri)
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'backend/app/lib/bulk_import/import_digital_objects.rb', line 86 def check_row err_arr = [] begin if @row_hash["ao_ref_id"].nil? && @row_hash["ao_uri"].nil? err_arr.push I18n.t("bulk_import.error.no_uri_or_ref") end end normalize_publish_column(@row_hash) normalize_publish_column(@row_hash, 'digital_object_link_publish') normalize_publish_column(@row_hash, 'thumbnail_publish') err_arr.join("; ") end |
#create_instance(ao) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'backend/app/lib/bulk_import/import_digital_objects.rb', line 14 def create_instance(ao) dig_instance = nil begin dig_instance = @doh.create(@row_hash["digital_object_title"], @row_hash["thumbnail"], @row_hash["digital_object_link"], @row_hash["digital_object_id"], @row_hash["publish"], ao, @report, @row_hash['digital_object_link_publish'], @row_hash['thumbnail_publish']) rescue Exception => e @report.add_errors(e.) end if dig_instance && !@validate_only # only try to save if not validate only ao.instances ||= [] ao.instances << dig_instance begin ao = ao_save(ao) @report.add_info(I18n.t("bulk_import.dig_assoc")) rescue BulkImportException => ee @report.add_errors(I18n.t("bulk_import.error.dig_unassoc", :msg => ee.)) end end dig_instance end |
#initialize_handler_enums ⇒ Object
99 100 101 |
# File 'backend/app/lib/bulk_import/import_digital_objects.rb', line 99 def initialize_handler_enums @doh = DigitalObjectHandler.new(@current_user, @validate_only) end |
#log_row(row) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'backend/app/lib/bulk_import/import_digital_objects.rb', line 68 def log_row(row) unless row.archival_object_id.nil? log_obj = I18n.t("bulk_import.log_obj", :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("bulk_import.log_info", :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 ⇒ Object
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 |
# File 'backend/app/lib/bulk_import/import_digital_objects.rb', line 35 def process_row ret_str = "" errs = [] begin resource_match(@resource, @row_hash["ead"], @row_hash["res_uri"]) rescue Exception => e errs << e. end errs << check_row errs.reject!(&:empty?) if !@validate_only && !errs.empty? err = errs.join("; ") raise BulkImportException.new(I18n.t("bulk_import.row_error", :row => @counter, :errs => err)) end ao = verify_ao(@row_hash["ao_ref_id"], @row_hash["ao_uri"], errs) if ao.nil? && !@validate_only err = errs.join("; ") raise BulkImportException.new(I18n.t("bulk_import.error.bad_ao", :errs => err)) end digital_instance = create_instance(ao) if !digital_instance & @validate_only @report.add_errors(errs.join("; ")) if !errs.empty? @report.add_errors(I18n.t("bulk_import.object_not_created_be", :what => I18n.t("bulk_import.dig"))) elsif !errs.empty? err = errs.join("; ") @report.add_errors(I18n.t("bulk_import.error.dig_unassoc", :msg => err)) end @created_refs.concat( [ao.uri, digital_instance.digital_object['ref']] ) if ao && digital_instance && !@validate_only digital_instance end |
#verify_ao(ref_id, uri, errs) ⇒ Object
any problem here would result in the digital object not being created
104 105 106 107 108 109 110 111 112 113 |
# File 'backend/app/lib/bulk_import/import_digital_objects.rb', line 104 def verify_ao(ref_id, uri, errs) result = archival_object_from_ref_or_uri(ref_id, uri) ao = result[:ao] if ao.nil? errs << I18n.t("bulk_import.error.bad_ao", :errs => result[:errs]) else @report.add_archival_object(ao) end ao end |