Class: NotesHandler
- Defined in:
- backend/app/lib/bulk_import/notes_handler.rb
Constant Summary collapse
- @@ao_note_types =
{}
- @@do_note_types =
{}
Constants inherited from Handler
Constants included from JSONModel
JSONModel::REFERENCE_KEY_REGEX
Instance Method Summary collapse
-
#ao_note_types ⇒ Object
-
#bib_note ⇒ Object
-
#create_note(type, note_label, content, publish, dig_obj = false, b_date = nil, e_date = nil, local_restriction = nil) ⇒ Object
-
#do_note_types ⇒ Object
-
#initialize ⇒ NotesHandler
constructor
A new instance of NotesHandler.
-
#wellformed(note) ⇒ Object
Methods inherited from Handler
#clear, #save, #search, #stored
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 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 ⇒ NotesHandler
Returns a new instance of NotesHandler.
5 6 7 8 9 10 11 12 |
# File 'backend/app/lib/bulk_import/notes_handler.rb', line 5 def initialize if @@ao_note_types.empty? @@ao_note_types = ao_note_types end if @@do_note_types.empty? @@do_note_types = do_note_types end end |
Instance Method Details
#ao_note_types ⇒ 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/notes_handler.rb', line 14 def ao_note_types note_types = bib_note JSONModel.enum_values(JSONModel(:note_singlepart).schema["properties"]["type"]["dynamic_enum"]).each do |type| note_types[type] = { :target => :note_singlepart, :enum => JSONModel(:note_singlepart).schema["properties"]["type"]["dynamic_enum"], :value => type, :i18n => I18n.t("enumerations.#{JSONModel(:note_singlepart).schema["properties"]["type"]["dynamic_enum"]}.#{type}", :default => type), } end JSONModel.enum_values(JSONModel(:note_multipart).schema["properties"]["type"]["dynamic_enum"]).each do |type| note_types[type] = { :target => :note_multipart, :enum => JSONModel(:note_multipart).schema["properties"]["type"]["dynamic_enum"], :value => type, :i18n => I18n.t("enumerations.#{JSONModel(:note_multipart).schema["properties"]["type"]["dynamic_enum"]}.#{type}", :default => type), } end note_types end |
#bib_note ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'backend/app/lib/bulk_import/notes_handler.rb', line 35 def bib_note note_types = { "bibliography" => { :target => :note_bibliography, :value => "bibliography", :i18n => I18n.t("enumerations._note_types.bibliography", :default => "bibliography"), }, } note_types end |
#create_note(type, note_label, content, publish, dig_obj = false, b_date = nil, e_date = nil, local_restriction = nil) ⇒ Object
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 |
# File 'backend/app/lib/bulk_import/notes_handler.rb', line 46 def create_note(type, note_label, content, publish, dig_obj = false, b_date = nil, e_date = nil, local_restriction = nil) note_types = dig_obj ? @@do_note_types : @@ao_note_types note_type = note_types[type] if note_type.nil? raise BulkImportException.new(I18n.t("bulk_import.error.bad_note_type", :type => type)) end note = JSONModel(note_type[:target]).new unless (note_label = note_label.to_s.strip).empty? note.label = note_label end note.publish = publish note.type = note_type[:value] begin wellformed(content) rescue Exception => e raise BulkImportException.new(I18n.t("bulk_import.error.bad_note", :type => note_type[:value], :msg => e.)) end # if the target is multipart, then the data goes in a JSONMODEL(:note_text).content;, which is pushed to the note.subnote array; otherwise it's just pushed to the note.content array if note_type[:target] == :note_multipart inner_note = JSONModel(:note_text).new inner_note.content = content inner_note.publish = publish note.subnotes.push inner_note else note.content.push content end # ANW-1115 add dates to access restriction notes if b_date || e_date note.rights_restriction = { 'begin' => b_date, 'end' => e_date, 'local_access_restriction_type' => [local_restriction].compact, } end # For some reason, just having the JSONModel doesn't work; convert to hash note.to_hash end |
#do_note_types ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'backend/app/lib/bulk_import/notes_handler.rb', line 84 def do_note_types note_types = bib_note # Digital object/digital object component JSONModel.enum_values(JSONModel(:note_digital_object).schema["properties"]["type"]["dynamic_enum"]).each do |type| note_types[type] = { :target => :note_digital_object, :enum => JSONModel(:note_digital_object).schema["properties"]["type"]["dynamic_enum"], :value => type, :i18n => I18n.t("enumerations.#{JSONModel(:note_digital_object).schema["properties"]["type"]["dynamic_enum"]}.#{type}", :default => type), } end note_types end |
#wellformed(note) ⇒ Object
98 99 100 101 102 |
# File 'backend/app/lib/bulk_import/notes_handler.rb', line 98 def wellformed(note) if note.match("</?[a-zA-Z]+>") frag = Nokogiri::XML("<root xmlns:xlink='https://www.w3.org/1999/xlink'>#{note}</root>") { |config| config.strict } end end |