Class: NotesHandler
- Inherits:
-
Handler
show all
- Defined in:
- backend/app/lib/bulk_import/notes_handler.rb
Constant Summary
collapse
- @@ao_note_types =
{}
- @@do_note_types =
{}
Constants inherited
from Handler
Handler::DISAMB_STR
Instance Method Summary
collapse
Methods inherited from Handler
#clear, #save, #search, #stored
Constructor Details
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
83
84
85
86
87
88
89
90
91
92
93
|
# 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.message))
end
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
unless local_restriction.nil?
note.rights_restriction = {
'local_access_restriction_type' => [local_restriction].compact,
}
end
unless b_date.nil?
note.rights_restriction = {} if note.rights_restriction.nil?
note.rights_restriction['begin'] = b_date
end
unless e_date.nil?
note.rights_restriction = {} if note.rights_restriction.nil?
note.rights_restriction['end'] = e_date
end
note.to_hash
end
|
#do_note_types ⇒ Object
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'backend/app/lib/bulk_import/notes_handler.rb', line 95
def do_note_types
note_types = bib_note
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
|
109
110
111
112
113
|
# File 'backend/app/lib/bulk_import/notes_handler.rb', line 109
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
|