Skip to content

Commit

Permalink
roles are now attributes of the wiki link
Browse files Browse the repository at this point in the history
  • Loading branch information
jmlagace committed Jul 7, 2016
1 parent ce16e96 commit bcd5ec3
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 52 deletions.
6 changes: 2 additions & 4 deletions app/models/artist_recording_wiki_link.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
class ArtistRecordingWikiLink < RecordingWikiLink
include Mongoid::Document

field :role, type:String

define_signed_as Artist, :recording_wiki_links

def role
searchref[:role]
end

class SearchQuery < self.superclass::SearchQuery
def self.query_expressions
super.merge({
Expand Down
5 changes: 3 additions & 2 deletions app/models/artist_wiki_link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class ArtistWikiLink < WikiLink
include Mongoid::Document

set_reference_class Artist
cache_attributes :name, :surname, :given_name, :birth_date, :birth_location
cache_attributes :name, :surname, :given_name, :birth_date, :birth_location, :is_group

field :start_date, type: String
field :end_date, type: String
Expand Down Expand Up @@ -40,7 +40,8 @@ class SearchQuery < ::SearchQuery
birth_date: :date,
birth_location: :text,
death_date: :date,
death_location: :text
death_location: :text,
is_group: :boolean
}
def self.query_expressions
superclass.query_expressions.merge QUERY_ATTRS
Expand Down
24 changes: 10 additions & 14 deletions app/models/search_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,17 @@ def []=(var_name,value)
end

def q(separator=" ")
unless @q
filled_fields = self.filled_query_fields
values = []
@field_order.each {|var_name|
filled_fields.delete(var_name.to_sym)
values << self.full_field(var_name)
}

filled_fields.each {|var_name|
values << self.full_field(var_name)
}
@q = values.join(separator)
end
filled_fields = self.filled_query_fields
values = []
@field_order.each {|var_name|
filled_fields.delete(var_name.to_sym)
values << self.full_field(var_name)
}

@q
filled_fields.each {|var_name|
values << self.full_field(var_name)
}
values.join(separator)
end

def url_encoded
Expand Down
2 changes: 1 addition & 1 deletion app/views/artists/_search_result.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- search_result.each do |artist|
%tr
%td
= link_to artist.name, artist_path(artist)
= artist_wiki_link_path(artist.to_wiki_link)
%td
- if (artist.birth_date != "0-00-00") then
= artist.birth_date
Expand Down
6 changes: 3 additions & 3 deletions app/views/artists/show.haml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
%th= WorkWikiLink.human_attribute_name("role")
%tbody
-# @artist.grouped_work_wiki_links.sort{|a,b| ((a.date_written <=> b.date_written) || 1) }.each do |wwl|
- @artist.work_wiki_links.sort{|a,b| ((a.date_written <=> b.date_written) || 1) }.each do |wwl|
- @artist.work_wiki_links.sort_by{|a| [a.date_written, a.title]}.each do |wwl|

%tr
%td= work_wiki_link_path(wwl)
Expand Down Expand Up @@ -77,12 +77,12 @@
%th= Recording.human_attribute_name("duration")
%th= Recording.human_attribute_name("role")
%tbody
- @artist.recording_wiki_links.sort{|a,b| ((a.recording_date <=> b.recording_date) || 1) }.each do |rwl|
- @artist.recording_wiki_links.sort_by{|a| [a.recording_date] }.each do |rwl|
%tr
%td= recording_wiki_link_path(rwl)
%td= rwl.recording_date
%td= rwl.duration
%td= rwl.recording.artist_wiki_links.where(artist_id: @artist.id).collect{|awl| awl.role }.join(", ").html_safe
%td= rwl.role

%h2= Release.model_name.human.pluralize
- if @artist.release_wiki_links.size == 0
Expand Down
2 changes: 1 addition & 1 deletion app/views/recordings/_search_result.haml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
%tbody
- search_result.each do |recording|
%tr
%td= link_to recording.title, recording_path(recording)
%td= recording_wiki_link_path(recording.to_wiki_link)
%td= recording.recording_date
%td= recording.duration
%td= recording.artist_wiki_links.collect{|awl| artist_wiki_link_path(awl) }.join(", ").html_safe
Expand Down
2 changes: 1 addition & 1 deletion app/views/releases/_search_result.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- search_result.each do |release|
%tr
%td
= link_to release.title, release_path(release)
= release_wiki_link_path(release.to_wiki_link)
%td
= release.artist_wiki_links.collect{|awl| artist_wiki_link_path(awl) }.join(", ").html_safe
%td
Expand Down
2 changes: 1 addition & 1 deletion app/views/works/_search_result.haml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
%tbody
- search_result.each do |work|
%tr
%td= link_to work.title, work_path(work)
%td= work_wiki_link_path(work.to_wiki_link)
%td= work.date_written
%td= work.language_name
%td= work.artist_wiki_links.collect{|awl| artist_wiki_link_path(awl) }.join(", ").html_safe
Expand Down
56 changes: 31 additions & 25 deletions lib/mdb_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def import_artists
:birth_location => l["LieuNaissance"],
:death_date => l["DateDeces"],
:death_location => l["LieuDécès"],
:is_group => l["Collectif"] }
:is_group => (l["Collectif"].to_i == 1) }

unless ["0","",nil].include?(l["Remarques"])
params[:supplementary_sections] = [SupplementarySection.new({:title=>"Notes biographiques",:content=>l["Remarques"]})]
Expand Down Expand Up @@ -252,14 +252,14 @@ def import_works_artists

::Work.disable_tracking {
::Artist.disable_tracking {
artists_works = Hash.new{|h,k| h[k]=[]}
works_artists = Hash.new{|h,k| h[k]=[]}
artists_works = Hash.new{|h,k| h[k]=Hash.new{|h,k| h[k] = {ref: k, roles: []}}}
works_artists = Hash.new{|h,k| h[k]=Hash.new{|h,k| h[k] = {ref: k, roles: []}}}

puts "pre-loading to speed up updates (1 of 3)"
MdbImporter.new("Lien Artiste Auteur-compositeur").each{|l|
if @work_filter.include?(l) and @artist_filter.include?(l)
artists_works[l["RefArtiste"]] << {ref: l["RefPiece"], role: l["RefRole"]}
works_artists[l["RefPiece"]] << {ref: l["RefArtiste"], role: l["RefRole"]}
artists_works[l["RefArtiste"]][l["RefPiece"]][:roles] << l["RefRole"]
works_artists[l["RefPiece"]][l["RefArtiste"]][:roles] << l["RefRole"]
end
}

Expand All @@ -269,14 +269,14 @@ def import_works_artists
w = Work.where(:origworkid => workid).first || raise("Cannot find work for id #{workid}")
artists = {}.tap {|h|
# .extras(:hint => {:origartistid => 1})
Artist.where(:origartistid.in => (artist_roles.collect{|a| a[:ref]})).each {|a|
Artist.where(:origartistid.in => (artist_roles.collect{|k,a| a[:ref]})).each {|a|
h[a.origartistid] = a
}
}

awls = artist_roles.collect {|artist|
awls = artist_roles.collect {|k,artist|
a = artists[artist[:ref]] || raise("Cannot find artist for id #{artistid}")
a.to_wiki_link(WorkArtistWikiLink, {role: self.roles[artist[:role]]})
a.to_wiki_link(WorkArtistWikiLink, {role: artist[:roles].collect{|role| self.roles[role] }.join(", ") })
}
w.artist_wiki_links = awls
w.save!
Expand All @@ -290,14 +290,14 @@ def import_works_artists
a = Artist.where(:origartistid => artistid).extras(:hint => {:origartistid => 1}).first || raise("Cannot find artist for id #{artistid}")

works = {}.tap {|h|
Work.where(:origworkid.in => (work_roles.collect{|w| w[:ref]})).extras(:hint => {:origworkid => 1}).each {|w|
Work.where(:origworkid.in => (work_roles.collect{|k,w| w[:ref]})).extras(:hint => {:origworkid => 1}).each {|w|
h[w.origworkid] = w
}
}

awls = work_roles.collect {|work|
awls = work_roles.collect {|k,work|
w = works[work[:ref]] || raise("Cannot find work for id #{workid}")
w.to_wiki_link(ArtistWorkWikiLink, {role: self.roles[work[:role]]})
w.to_wiki_link(ArtistWorkWikiLink, {role: work[:roles].collect{|role| self.roles[role] }.join(", ") })
}
a.work_wiki_links = awls
a.save!
Expand Down Expand Up @@ -366,14 +366,14 @@ def import_recordings_artists
::Recording.disable_tracking {
::Artist.disable_tracking {

artists_recordings = Hash.new{|h,k| h[k]=[]}
recordings_artists = Hash.new{|h,k| h[k]=[]}
artists_recordings = Hash.new{|h,k| h[k]=Hash.new{|h,k| h[k] = {ref: k, roles: []}}}
recordings_artists = Hash.new{|h,k| h[k]=Hash.new{|h,k| h[k] = {ref: k, roles: []}}}

puts "pre-loading to speed up updates (1 of 3)"
MdbImporter.new("Lien Artiste Interprete").each{|l|
if @recording_filter.include?(l, "RéfVersion") and @artist_filter.include?(l) and @recordings_loaded.include?(l["RéfVersion"])
artists_recordings[l["RefArtiste"]] << {ref: l["RéfVersion"], role: l["RefRole"]}
recordings_artists[l["RéfVersion"]] << {ref: l["RefArtiste"], role: l["RefRole"]}
artists_recordings[l["RefArtiste"]][l["RéfVersion"]][:roles] << l["RefRole"]
recordings_artists[l["RéfVersion"]][l["RefArtiste"]][:roles] << l["RefRole"]
end
}

Expand All @@ -383,14 +383,14 @@ def import_recordings_artists
r = Recording.where(:origrecordingid => recordingid).first || raise("Cannot find recording for id #{recordingid}")
artists = {}.tap {|h|
# .extras(:hint => {:origartistid => 1})
Artist.where(:origartistid.in => (artist_roles.collect{|a| a[:ref]})).each {|a|
Artist.where(:origartistid.in => (artist_roles.collect{|k,a| a[:ref]})).each {|a|
h[a.origartistid] = a
}
}

awls = artist_roles.collect {|artist|
awls = artist_roles.collect {|k,artist|
a = artists[artist[:ref]] || raise("Cannot find artist for id #{artist[:ref]}")
a.to_wiki_link(RecordingArtistWikiLink, {role: self.roles[artist[:role]]})
a.to_wiki_link(RecordingArtistWikiLink, {role: artist[:roles].collect{|role| self.roles[role] }.join(", ") })
}
r.artist_wiki_links = awls
r.save!
Expand All @@ -403,14 +403,14 @@ def import_recordings_artists
a = Artist.where(:origartistid => artistid).extras(:hint => {:origartistid => 1}).first || raise("Cannot find artist for id #{artistid}")

recordings = {}.tap {|h|
Recording.where(:origrecordingid.in => (recording_roles.collect{|w| w[:ref]})).extras(:hint => {:origrecordingid => 1}).each {|r|
Recording.where(:origrecordingid.in => (recording_roles.collect{|k,w| w[:ref]})).extras(:hint => {:origrecordingid => 1}).each {|r|
h[r.origrecordingid] = r
}
}

awls = recording_roles.collect {|recording|
awls = recording_roles.collect {|k,recording|
r = recordings[recording[:ref]] || raise("Cannot find recording for id #{recording[:ref]}")
r.to_wiki_link(ArtistRecordingWikiLink, {role: self.roles[recording[:role]]})
r.to_wiki_link(ArtistRecordingWikiLink, {role: recording[:roles].collect{|role| self.roles[role] }.join(", ") })
}
a.recording_wiki_links = awls
a.save!
Expand All @@ -436,13 +436,19 @@ def import_releases
params = {:origalbumid => l["RefAlbum"],
:title => l["TitreAlbum"],
:date_released => l["Annee"],
:label => self.labels[l["RefEtiquette"]],
:media_type => self.media_types[l["RefFormat"]],
:reference_code => l["NoAlbum"],
:alpha_ordering => l["Ordre1Alpha"],
:numerical_ordering => l["Ordre2Num"],
:artist_wiki_links => [artist.to_wiki_link(ReleaseArtistWikiLink)]
:numerical_ordering => l["Ordre2Num"]
}
unless l["RefEtiquette"].to_i == 0
params[:label] = self.labels[l["RefEtiquette"]]
end
unless l["RefFormat"].to_i == 0
params[:media_type] = self.media_types[l["RefFormat"]]
end
if artist
params[:artist_wiki_links] = [artist.to_wiki_link(ReleaseArtistWikiLink)]
end
unless ["0","",nil].include?(l["Remarques"])
params[:supplementary_sections] = [SupplementarySection.new({:title=>"Notes",:content=>l["Remarques"]})]
end
Expand Down

0 comments on commit bcd5ec3

Please sign in to comment.