Skip to content

Commit

Permalink
Fix bug whereby note_bibliography and note_index causes ladybird expo…
Browse files Browse the repository at this point in the history
…rt to throw an error. Also include singlepart notes in the note column
  • Loading branch information
payten committed Jul 29, 2020
1 parent 287e49e commit f13846b
Showing 1 changed file with 41 additions and 28 deletions.
69 changes: 41 additions & 28 deletions backend/model/ladybird_export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -449,40 +449,29 @@ def prepare_notes
Sequel.as(:note__resource_id, :resource_id),
Sequel.as(:note__notes, :note))
.each do |row|
parsed = parse_note(row)

next if parsed.nil?

# group notes by type
if row[:archival_object_id]
@notes[row[:archival_object_id]] ||= {}

parsed = parse_note(row)

next if parsed.nil?

@notes[row[:archival_object_id]][parsed.fetch('type')] ||= []
@notes[row[:archival_object_id]][parsed.fetch('type')] << parsed.fetch('notes')
@notes[row[:archival_object_id]][parsed.fetch('type')] << parsed.fetch('note')
elsif row[:resource_id]
@resource_notes[row[:resource_id]] ||= {}

parsed = parse_note(row)

next if parsed.nil?

@resource_notes[row[:resource_id]][parsed.fetch('type')] ||= []
@resource_notes[row[:resource_id]][parsed.fetch('type')] << parsed.fetch('notes')
@resource_notes[row[:resource_id]][parsed.fetch('type')] << parsed.fetch('note')
end
end
end

def parse_note(row)
note = ASUtils.json_parse(row[:note])

type = note.fetch('type')
subnotes = note.fetch('subnotes', nil)

return unless subnotes

{
'type' => type,
'notes' => subnotes.collect{|n| n.fetch('content', nil)}.compact
'type' => note.fetch('type', note.fetch('jsonmodel_type')),
'note' => note.to_h,
}
end

Expand Down Expand Up @@ -646,23 +635,45 @@ def host_note(row)

def note(row)
notes_for_archival_object(row[:archival_object_id])
.map{|type, content|
.map{|type, notes|
next if type == 'scopecontent'
next if type == 'accessrestrict'
next if type == 'prefercite'
content.flatten

notes_to_text(notes)
}
.flatten
.compact
.join(NEW_LINE_SEPARATOR)
end

def notes_to_text(notes)
notes
.map{|note_json| note_to_text(note_json)}
.compact
.map{|note_text| strip_html(note_text)}
end

def note_to_text(note_json)
if note_json['jsonmodel_type'] == 'note_singlepart'
note_json.fetch('content', []).join(NEW_LINE_SEPARATOR)
elsif note_json['jsonmodel_type'] == 'note_multipart'
note_json.fetch('subnotes', []).map{|subnote|
note_to_text(subnote)
}.compact.join(NEW_LINE_SEPARATOR)
elsif note_json['jsonmodel_type'] == 'note_text'
note_json['content']
else
# unsupported note type
end
end

def abstract(row)
notes_for_archival_object(row[:archival_object_id])
.map{|type, content|
.map{|type, notes|
next unless type == 'scopecontent'
content.flatten

notes_to_text(notes)
}
.compact
.flatten
Expand Down Expand Up @@ -721,19 +732,21 @@ def ead_location(row)

def citation_note(row)
archival_object_citation = notes_for_archival_object(row[:archival_object_id])
.map{|type, content|
.map{|type, notes|
next unless type == 'prefercite'
content.flatten

notes_to_text(notes)
}
.compact
.flatten

return archival_object_citation.join(NEW_LINE_SEPARATOR) unless archival_object_citation.empty?

notes_for_resource(row[:resource_id])
.map{|type, content|
.map{|type, notes|
next unless type == 'prefercite'
content.flatten

notes_to_text(notes)
}
.compact
.flatten
Expand Down

0 comments on commit f13846b

Please sign in to comment.