First version with complete sync.
This commit is contained in:
parent
2d2b4f91f0
commit
dad45abcda
|
@ -13,7 +13,12 @@ module FguSyncPlugin
|
|||
def self.close
|
||||
@client.close
|
||||
end
|
||||
|
||||
def self.localize_data(d)
|
||||
["zh_tw", "en"].map{|l| [l, d]}.to_h
|
||||
end
|
||||
def self.parse_date(d)
|
||||
(d.present? ? (Date.parse(d) rescue nil) : nil)
|
||||
end
|
||||
def self.camelize(str)
|
||||
str.split('_').map{|v| v.capitalize}.join(' ')
|
||||
end
|
||||
|
@ -45,20 +50,20 @@ module FguSyncPlugin
|
|||
data.each_with_index do |dt, idx|
|
||||
rss2id = dt["journal_id"]
|
||||
|
||||
pd = Date.parse(dt["publication_date"]) rescue Date.today
|
||||
paper_title = {"en" => dt["paper_title"],"zh_tw" => dt["paper_title"]}
|
||||
journal_title = {"en" => dt["journal_title"],"zh_tw" => dt["journal_title"]}
|
||||
pd = self.parse_date(dt["publication_date"])
|
||||
paper_title = self.localize_data(dt["paper_title"])
|
||||
journal_title = self.localize_data(dt["journal_title"])
|
||||
from_to = dt["from_to"].split("-")
|
||||
from_to[1] = "" if !from_to[1].present?
|
||||
all_authors = [dt["author1"],dt["author2"],dt["author3"],dt["author4"]]
|
||||
all_authors.delete("")
|
||||
authors = {"en" => all_authors.join(", "), "zh_tw" => all_authors.join(", ")}
|
||||
authors = self.localize_data(all_authors.join(", "))
|
||||
note = dt["department"] + " " + dt["country"] + " " + dt["note"]
|
||||
|
||||
if !dt["paper_level"].empty?
|
||||
level = JournalLevel.where(:title => dt["paper_level"]).first rescue nil
|
||||
if level.nil?
|
||||
level = JournalLevel.create(:key => "key_#{idx}", :title_translations => {"en" => dt["paper_level"], "zh_tw" => dt["paper_level"]})
|
||||
level = JournalLevel.create(:key => "key_#{idx}", :title_translations => self.localize_data(dt["paper_level"]))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -71,7 +76,7 @@ module FguSyncPlugin
|
|||
|
||||
jp = JournalPaper.where(:rss2_id => rss2id).first rescue nil
|
||||
jp_data = {
|
||||
:publication_date => pd, :rss2_id => rss2id, :year => pd.strftime("%Y"),
|
||||
:publication_date => pd, :rss2_id => rss2id, :year => (pd ? pd.strftime("%Y") : ""),
|
||||
:authors_translations => authors, :paper_title_translations => paper_title,
|
||||
:journal_title_translations => journal_title, :vol_no => dt["vol_no"], :issue_no => dt["issue_no"],
|
||||
:note => note, :form_to_start => from_to[0], :form_to_end => from_to[1]
|
||||
|
@ -107,17 +112,17 @@ module FguSyncPlugin
|
|||
data.each_with_index do |dt, idx|
|
||||
rss2id = dt["conf_id"]
|
||||
|
||||
start_date = Date.parse(dt["start_date"]) rescue Date.today
|
||||
end_date = Date.parse(dt["end_date"]) rescue Date.today
|
||||
paper_title = {"en" => dt["paper_title"],"zh_tw" => dt["paper_title"]}
|
||||
conference_title = {"en" => dt["conference_name"],"zh_tw" => dt["conference_name"]}
|
||||
start_date = self.parse_date(dt["start_date"])
|
||||
end_date = self.parse_date(dt["end_date"])
|
||||
paper_title = self.localize_data(dt["paper_title"])
|
||||
conference_title = self.localize_data(dt["conference_name"])
|
||||
authors = [dt["author1"],dt["author2"],dt["author3"],dt["author4"]]
|
||||
authors.delete("")
|
||||
authors = {"en" => authors.join(", "), "zh_tw" => authors.join(", ")}
|
||||
authors = self.localize_data(authors.join(", "))
|
||||
note = dt["department"] + " " + dt["note"]
|
||||
|
||||
cp = WritingConference.where(:rss2_id => rss2id).first rescue nil
|
||||
cp_data = {:period_start_date => start_date, :period_end_date => end_date, :rss2_id => rss2id, :year => end_date.strftime("%Y"), :authors_translations => authors, :paper_title_translations => paper_title, :conference_title_translations => conference_title, :note => note, :location_translations => {"en" => dt["location"], "zh_tw" => dt["location"]}}
|
||||
cp_data = {:period_start_date => start_date, :period_end_date => end_date, :rss2_id => rss2id, :year => (start_date ? start_date.strftime("%Y") : ""), :authors_translations => authors, :paper_title_translations => paper_title, :conference_title_translations => conference_title, :note => note, :location_translations => self.localize_data(dt["location"])}
|
||||
if cp.nil?
|
||||
cp = WritingConference.new(cp_data)
|
||||
puts "Saving new conference."
|
||||
|
@ -135,37 +140,6 @@ module FguSyncPlugin
|
|||
puts "*********************************************"
|
||||
end
|
||||
|
||||
# def self.sync_research_papers(staff_id,mp)
|
||||
# data = self.get_research_papers(staff_id)
|
||||
# puts "Starting Research Paper for staff #{staff_id}."
|
||||
# if !data.nil?
|
||||
# researches = data
|
||||
# total = researches.count rescue 0
|
||||
# return if total == 0
|
||||
# Research.where(:rss2_id.nin => ([nil,''] + researches.map{|research| research["rss_id"]}),member_profile_id: mp.id).destroy
|
||||
# researches.each_with_index do |research,index|
|
||||
# if !research.blank?
|
||||
# res = Research.where(:rss2_id => research["rss_id"]).first rescue nil
|
||||
# if res.nil?
|
||||
# res = Research.new(rss2_id: research["rss_id"])
|
||||
# puts "Syncing new : " + ((100 * (index +1)) / total).to_s + "%"
|
||||
# puts "rss2_id: #{research["rss_id"]}" if @debug_mode
|
||||
# else
|
||||
# puts "Updating old : " + ((100 * (index +1)) / total).to_s + "%"
|
||||
# end
|
||||
# res.publish_date = "#{research["publication_year"]}/#{research["publication_month"]}/01"
|
||||
# res.url = research["url"]
|
||||
# res.year = research["publication_year"]
|
||||
# res.research_title_translations = research["title"]
|
||||
# res.member_profile = mp
|
||||
# res.save
|
||||
# sleep 0.1
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# puts "Research Paper for staff #{staff_id} completed."
|
||||
# end
|
||||
|
||||
def self.sync_books(staff_id,mp)
|
||||
puts "*********************************************"
|
||||
puts "Syncing book for #{staff_id}"
|
||||
|
@ -177,30 +151,30 @@ module FguSyncPlugin
|
|||
data.each_with_index do |dt, idx|
|
||||
rss2id = dt["book_id"]
|
||||
|
||||
pd = Date.parse(dt["date_of_publication"]) rescue Date.today
|
||||
book_title = {"en" => dt["book_title"],"zh_tw" => dt["book_title"]}
|
||||
publisher = {"en" => dt["publisher"],"zh_tw" => dt["publisher"]}
|
||||
pd = self.parse_date(dt["date_of_publication"])
|
||||
book_title = self.localize_data(dt["book_title"])
|
||||
publisher = self.localize_data(dt["publisher"])
|
||||
authors = [dt["author1"],dt["author2"],dt["author3"],dt["author4"]]
|
||||
authors.delete("")
|
||||
authors = {"en" => authors.join(", "), "zh_tw" => authors.join(", ")}
|
||||
authors = self.localize_data(authors.join(", "))
|
||||
note = dt["department"] + " " + dt["location"] + " " + dt["note"]
|
||||
|
||||
if !dt["author_type"].empty?
|
||||
authortype = BookAuthorType.where(:title => dt["author_type"]).first rescue nil
|
||||
if authortype.nil?
|
||||
authortype = BookAuthorType.create(:title_translations => {"en" => dt["author_type"], "zh_tw" => dt["author_type"]})
|
||||
authortype = BookAuthorType.create(:title_translations => self.localize_data(dt["author_type"]))
|
||||
end
|
||||
end
|
||||
|
||||
if !dt["book_type"].empty?
|
||||
type = BookType.where(:title => dt["book_type"]).first rescue nil
|
||||
if type.nil?
|
||||
type = BookType.create(:title_translations => {"en" => dt["book_type"], "zh_tw" => dt["book_type"]})
|
||||
type = BookType.create(:title_translations => self.localize_data(dt["book_type"]))
|
||||
end
|
||||
end
|
||||
|
||||
book = Book.where(:rss2_id => rss2id).first rescue nil
|
||||
book_data = {:publish_date => pd, :rss2_id => rss2id, :year => pd.strftime("%Y"), :authors_translations => authors, :publisher_translations => publisher, :book_title_translations => book_title, :isbn => dt["isbn"], :note => note, :language => dt["language"], :member_profile => mp}
|
||||
book_data = {:publish_date => pd, :rss2_id => rss2id, :year => (pd ? pd.strftime("%Y") : ""), :authors_translations => authors, :publisher_translations => publisher, :book_title_translations => book_title, :isbn => dt["isbn"], :note => note, :language => dt["language"], :member_profile => mp}
|
||||
if book.nil?
|
||||
book = Book.new(book_data)
|
||||
puts "Saving new book."
|
||||
|
@ -230,11 +204,11 @@ module FguSyncPlugin
|
|||
puts "Deleting old data"
|
||||
Diploma.where(:member_profile_id => mp.id).destroy
|
||||
data.each_with_index do |dt, idx|
|
||||
start_date = Date.parse(dt["start_date"]) rescue Date.today
|
||||
end_date = Date.parse(dt["end_date"]) rescue Date.today
|
||||
school_name = {"en" => dt["school_name"], "zh_tw" => dt["school_name"]}
|
||||
department = {"en" => dt["department"], "zh_tw" => dt["department"]}
|
||||
degree = {"en" => dt["degree"], "zh_tw" => dt["degree"]}
|
||||
start_date = self.parse_date(dt["start_date"])
|
||||
end_date = self.parse_date(dt["end_date"])
|
||||
school_name = self.localize_data(dt["school_name"])
|
||||
department = self.localize_data(dt["department"])
|
||||
degree = self.localize_data(dt["degree"])
|
||||
Diploma.create(:start_date => start_date, :end_date => end_date, :school_name_translations => school_name, :department_translations => department, :degree_translations => degree, :member_profile => mp)
|
||||
puts "Diploma created."
|
||||
end
|
||||
|
@ -251,106 +225,182 @@ module FguSyncPlugin
|
|||
if data.count > 0
|
||||
puts "Data found."
|
||||
puts "Deleting old data"
|
||||
Experience.where(:member_profile_id => mp.id).destroy
|
||||
Experience.where(:member_profile_id => mp.id, :rss2_id.nin => ([nil,''] + data.map{|dt| dt["rss2_id"]})).destroy
|
||||
data.each_with_index do |dt, idx|
|
||||
start_date = Date.parse(dt["start_date"]) rescue Date.today
|
||||
end_date = Date.parse(dt["end_date"]) rescue Date.today
|
||||
organization_title = {"en" => dt["organization_title"], "zh_tw" => dt["organization_title"]}
|
||||
job_title = {"en" => dt["job_title"], "zh_tw" => dt["job_title"]}
|
||||
rss2_id = dt['rss2_id']
|
||||
start_date = self.parse_date(dt["start_date"])
|
||||
end_date = self.parse_date(dt["end_date"])
|
||||
organization_title = self.localize_data(dt["organization_title"])
|
||||
job_title = self.localize_data(dt["job_title"])
|
||||
if !dt["emp_type"].blank?
|
||||
type = ExperienceType.where(:title => dt["emp_type"]).first rescue nil
|
||||
if type.nil?
|
||||
type = ExperienceType.create(:title_translations => {"en" => dt["emp_type"], "zh_tw" => dt["emp_type"]})
|
||||
type = ExperienceType.create(:title_translations => self.localize_data(dt["emp_type"]))
|
||||
end
|
||||
end
|
||||
exp = Experience.new(:start_date => start_date, :end_date => end_date, :organizationt_title_translations => organization_title, :job_title_translations => job_title, :member_profile => mp)
|
||||
exp.experience_type = type if !type.nil?
|
||||
exp.save
|
||||
puts "Exp created."
|
||||
exp = Experience.where(:rss2_id => rss2_id).first
|
||||
exp_data = {:rss2_id => rss2_id, :start_date => start_date, :end_date => end_date, :organizationt_title_translations => organization_title, :job_title_translations => job_title, :member_profile => mp, :experience_type => type}
|
||||
if exp.nil?
|
||||
exp = Experience.create(exp_data)
|
||||
puts "Saving new Exp."
|
||||
else
|
||||
exp.update_attributes(exp_data)
|
||||
puts "Updating Exp #{exp.id}."
|
||||
end
|
||||
end
|
||||
end
|
||||
puts "Syncing experiences for #{staff_id} complete."
|
||||
puts "*********************************************"
|
||||
end
|
||||
|
||||
# def self.sync_projects(staff_id,mp)
|
||||
# data = self.get_projects(staff_id)
|
||||
# puts "Starting Projects for staff #{staff_id}."
|
||||
# if !data.nil?
|
||||
# projects = data
|
||||
# total = projects.count rescue 0
|
||||
# return if total == 0
|
||||
# Project.where(:rss2_id.nin => ([nil,''] + projects.map{|project| project["rss_id"]}),member_profile_id: mp.id).destroy
|
||||
# projects.each_with_index do |project,index|
|
||||
# next if project.blank?
|
||||
# proj = Project.where(:rss2_id => project["rss_id"]).first rescue nil
|
||||
# pt_title = [project["category"]["zh_tw"],project["category"]["en"]].compact rescue []
|
||||
# pt = ProjectType.where(:title.in => pt_title).first rescue nil
|
||||
# if pt.nil? && pt_title.count > 0
|
||||
# pt = ProjectType.new
|
||||
# pt.title_translations = project["category"]
|
||||
# pt.save
|
||||
# end
|
||||
# if proj.nil?
|
||||
# proj = Project.new(rss2_id: project["rss_id"])
|
||||
# puts "Syncing new : " + ((100 * (index +1)) / total).to_s + "%"
|
||||
# puts "rss2_id: #{project["rss_id"]}" if @debug_mode
|
||||
# else
|
||||
# puts "Updating old : " + ((100 * (index +1)) / total).to_s + "%"
|
||||
# end
|
||||
# proj.period_start_date = project["start_date"]
|
||||
# proj.period_end_date = project["end_date"]
|
||||
# proj.url = project["url"]
|
||||
# proj.year = project["year"]
|
||||
# proj.project_title_translations = project["title"]
|
||||
# proj.job_title_translations = project["job"]
|
||||
# proj.participator_translations = project["participator"]
|
||||
# proj.unit_translations = project["unit"]
|
||||
# proj.member_profile = mp
|
||||
# proj.project_type = pt
|
||||
# proj.save
|
||||
# sleep 0.1
|
||||
# end
|
||||
# end
|
||||
# puts "Projects for staff #{staff_id} completed."
|
||||
# end
|
||||
def self.sync_certificates(staff_id,mp)
|
||||
puts "*********************************************"
|
||||
puts "Syncing certificates for #{staff_id}"
|
||||
data = self.get_certificates(staff_id)
|
||||
I18n.locale = :zh_tw
|
||||
if data.count > 0
|
||||
puts "Data found."
|
||||
puts "Deleting old data"
|
||||
Certificate.where(:member_profile_id => mp.id, :rss2_id.nin => ([nil,''] + data.map{|dt| dt["rss2_id"]})).destroy
|
||||
data.each_with_index do |dt, idx|
|
||||
rss2_id = dt['rss2_id']
|
||||
issue_date = self.parse_date(dt["issue_date"])
|
||||
title_translations = self.localize_data(dt["title"])
|
||||
issued_by_translations = self.localize_data(dt["issued_by"])
|
||||
expiration_date = self.parse_date(dt["expiration_date"])
|
||||
year = (issue_date ? issue_date.strftime("%Y") : "")
|
||||
if !dt["certificate_type"].blank?
|
||||
type = CertificateCategory.where(:certificate_type => dt["certificate_type"]).first rescue nil
|
||||
if type.nil?
|
||||
type = CertificateCategory.create(:certificate_type_translations => self.localize_data(dt["certificate_type"]))
|
||||
end
|
||||
end
|
||||
cert = Certificate.where(:rss2_id => rss2_id).first
|
||||
cert_data = {:rss2_id => rss2_id, :issue_date => issue_date, :title_translations=> title_translations, :issued_by_translations => issued_by_translations,:expiration_date => expiration_date, :year => year, :member_profile => mp, :certificate_category => type}
|
||||
if cert.nil?
|
||||
cert = Certificate.create(cert_data)
|
||||
puts "Saving new Certificate."
|
||||
else
|
||||
cert.update_attributes(cert_data)
|
||||
puts "Updating Certificate #{exp.id}."
|
||||
end
|
||||
end
|
||||
end
|
||||
puts "Syncing certificates for #{staff_id} complete."
|
||||
puts "*********************************************"
|
||||
end
|
||||
|
||||
# def self.sync_honors(staff_id,mp)
|
||||
# data = self.get_honors(staff_id)
|
||||
# puts "Starting Honors for staff #{staff_id}."
|
||||
# if !data.nil?
|
||||
# honors = data
|
||||
# total = honors.count rescue 0
|
||||
# return if total == 0
|
||||
# Honor.where(:rss2_id.nin => ([nil,''] + honors.map{|honor| honor["rss_id"]}),member_profile_id: mp.id).destroy
|
||||
# honors.each_with_index do |honor,index|
|
||||
# next if honor.blank?
|
||||
# hon = Honor.where(:rss2_id => honor["rss_id"]).first rescue nil
|
||||
# ht_title = [honor["category"]["zh_tw"],honor["category"]["en"]].compact rescue []
|
||||
# ht = HonorType.where(:title.in => ht_title).first rescue nil
|
||||
# if ht.nil? && ht_title.count > 0
|
||||
# ht = HonorType.new
|
||||
# ht.title_translations = honor["category"]
|
||||
# ht.save
|
||||
# end
|
||||
# if hon.nil?
|
||||
# hon = Honor.new(rss2_id: honor["rss_id"])
|
||||
# puts "Syncing new : " + ((100 * (index +1)) / total).to_s + "%"
|
||||
# puts "rss2_id: #{honor["rss_id"]}" if @debug_mode
|
||||
# else
|
||||
# puts "Updating old : " + ((100 * (index +1)) / total).to_s + "%"
|
||||
# end
|
||||
# hon.award_name_translations = honor["title"]
|
||||
# hon.awarding_unit_translations = honor["unit"]
|
||||
# hon.year = honor["year"]
|
||||
# hon.honor_type = ht
|
||||
# hon.member_profile = mp
|
||||
# hon.save
|
||||
# sleep 0.1
|
||||
# end
|
||||
# end
|
||||
# puts "Honors for staff #{staff_id} completed."
|
||||
# end
|
||||
def self.sync_projects(staff_id,mp)
|
||||
puts "*********************************************"
|
||||
puts "Syncing projects for #{staff_id}"
|
||||
data = self.get_projects(staff_id)
|
||||
I18n.locale = :zh_tw
|
||||
if data.count > 0
|
||||
puts "Data found."
|
||||
puts "Deleting old data"
|
||||
Project.where(:member_profile_id => mp.id, :rss2_id.nin => ([nil,''] + data.map{|dt| dt["rss2_id"]})).destroy
|
||||
data.each_with_index do |dt, idx|
|
||||
rss2_id = dt["rss2_id"]
|
||||
project_title = self.localize_data(dt["project_title"])
|
||||
project_number = dt["project_number"]
|
||||
period_start_date = self.parse_date(dt["period_start_date"])
|
||||
period_end_date = self.parse_date(dt["period_end_date"])
|
||||
unit = self.localize_data(dt["unit"])
|
||||
participants = self.localize_data(dt["participants"])
|
||||
year = (period_start_date ? period_start_date.strftime("%Y") : "")
|
||||
prj = Project.where(:rss2_id => rss2_id).first
|
||||
prj_data = {:rss2_id => rss2_id,:project_title_translations => project_title, :project_number=> project_number, :period_start_date => period_start_date, :period_end_date => period_end_date, :unit_translations => unit, :participants_translations => participants, :year => year, :member_profile => mp}
|
||||
if prj.nil?
|
||||
prj = Project.create(prj_data)
|
||||
puts "Saving new Project."
|
||||
else
|
||||
prj.update_attributes(prj_data)
|
||||
puts "Updating Project #{prj.id}."
|
||||
end
|
||||
puts "Project created."
|
||||
end
|
||||
end
|
||||
puts "Syncing projects for #{staff_id} complete."
|
||||
puts "*********************************************"
|
||||
end
|
||||
|
||||
def self.sync_honors(staff_id,mp)
|
||||
puts "*********************************************"
|
||||
puts "Syncing honors for #{staff_id}"
|
||||
data = self.get_honors(staff_id)
|
||||
I18n.locale = :zh_tw
|
||||
if data.count > 0
|
||||
puts "Data found."
|
||||
puts "Deleting old data"
|
||||
Honor.where(:member_profile_id => mp.id, :rss2_id.nin => ([nil,''] + data.map{|dt| dt["rss2_id"]})).destroy
|
||||
data.each_with_index do |dt, idx|
|
||||
rss2_id = dt["rss2_id"]
|
||||
award_date = self.parse_date(dt["award_date"])
|
||||
award_name_translations = self.localize_data(dt["award_name"])
|
||||
country_translations = self.localize_data(dt["country"])
|
||||
ranking_translations = self.localize_data(dt["ranking"])
|
||||
honor_type = dt["honor_type"]
|
||||
awarding_body_translations = self.localize_data(dt["awarding_body"])
|
||||
awarding_unit_translations = self.localize_data(dt["awarding_unit"])
|
||||
year = (award_date ? award_date.strftime("%Y") : "")
|
||||
if !dt["honor_type"].blank?
|
||||
type = HonorType.where(:title => dt["honor_type"]).first rescue nil
|
||||
if type.nil?
|
||||
type = HonorType.create(:title_translations => self.localize_data(dt["honor_type"]))
|
||||
end
|
||||
end
|
||||
hon = Honor.where(:rss2_id => rss2_id).first
|
||||
hon_data = {:award_date => award_date, :award_name_translations=> award_name_translations, :country_translations => country_translations, :ranking_translations => ranking_translations, :awarding_body_translations => awarding_body_translations, :awarding_unit_translations => awarding_unit_translations, :year => year, :member_profile => mp, :honor_type => type}
|
||||
if hon.nil?
|
||||
hon = Honor.create(hon_data)
|
||||
puts "Saving new Honor."
|
||||
else
|
||||
hon.update_attributes(hon_data)
|
||||
puts "Updating Honor #{hon.id}."
|
||||
end
|
||||
puts "Honor created."
|
||||
end
|
||||
end
|
||||
puts "Syncing honors for #{staff_id} complete."
|
||||
puts "*********************************************"
|
||||
end
|
||||
|
||||
def self.sync_patents(staff_id,mp)
|
||||
puts "*********************************************"
|
||||
puts "Syncing patents for #{staff_id}"
|
||||
data = self.get_patents(staff_id)
|
||||
I18n.locale = :zh_tw
|
||||
if data.count > 0
|
||||
puts "Data found."
|
||||
puts "Deleting old data"
|
||||
Patent.where(:member_profile_id => mp.id, :rss2_id.nin => ([nil,''] + data.map{|dt| dt["rss2_id"]})).destroy
|
||||
data.each_with_index do |dt, idx|
|
||||
rss2_id = dt['rss2_id']
|
||||
patent_title = self.localize_data(dt["patent_title"])
|
||||
patent_country = self.localize_data(dt["patent_country"])
|
||||
publication_date = self.parse_date(dt["publication_date"])
|
||||
expiration_date = self.parse_date(dt["expiration_date"])
|
||||
if !dt["patent_type"].blank?
|
||||
type = PatentType.where(:title => dt["patent_type"]).first rescue nil
|
||||
if type.nil?
|
||||
type = PatentType.create(:title_translations => self.localize_data(dt["patent_type"]))
|
||||
end
|
||||
end
|
||||
year = (publication_date ? publication_date.strftime("%Y") : "")
|
||||
pat = Patent.where(:rss2_id => rss2_id).first
|
||||
pat_data = {:rss2_id => rss2_id, :patent_title_translations => patent_title, :patent_country_translations => patent_country, :publication_date => publication_date, :expiration_date => expiration_date, :year => year, :member_profile => mp, :patent_type => type}
|
||||
if pat.nil?
|
||||
pat = Patent.create(pat_data)
|
||||
puts "Saving new Patent."
|
||||
else
|
||||
pat.update_attributes(pat_data)
|
||||
puts "Updating Patent #{pat.id}."
|
||||
end
|
||||
end
|
||||
end
|
||||
puts "Syncing patents for #{staff_id} complete."
|
||||
puts "*********************************************"
|
||||
end
|
||||
|
||||
def self.sync_activities(staff_id,mp)
|
||||
puts "*********************************************"
|
||||
|
@ -360,25 +410,37 @@ module FguSyncPlugin
|
|||
if data.count > 0
|
||||
puts "Data found."
|
||||
puts "Deleting old data"
|
||||
Experience.where(:member_profile_id => mp.id).destroy
|
||||
Activity.where(:member_profile_id => mp.id, :rss2_id.nin => ([nil,''] + data.map{|dt| dt["rss2_id"]})).destroy
|
||||
data.each_with_index do |dt, idx|
|
||||
start_date = Date.parse(dt["start_date"]) rescue Date.today
|
||||
end_date = Date.parse(dt["end_date"]) rescue Date.today
|
||||
organization_title = {"en" => dt["organization_title"], "zh_tw" => dt["organization_title"]}
|
||||
job_title = {"en" => dt["job_title"], "zh_tw" => dt["job_title"]}
|
||||
if !dt["emp_type"].blank?
|
||||
type = ExperienceType.where(:title => dt["emp_type"]).first rescue nil
|
||||
if type.nil?
|
||||
type = ExperienceType.create(:title_translations => {"en" => dt["emp_type"], "zh_tw" => dt["emp_type"]})
|
||||
end
|
||||
rss2_id = dt['rss2_id']
|
||||
publish_date = self.parse_date(dt["publish_date"])
|
||||
updated_at = self.parse_date(dt["updated_at"])
|
||||
start_date = self.parse_date(dt["start_date"])
|
||||
end_date = self.parse_date(dt["end_date"])
|
||||
activity_name = self.localize_data(dt["activity_name"])
|
||||
work_title = self.localize_data(dt["work_title"])
|
||||
activity_organizer = self.localize_data(dt["activity_organizer"])
|
||||
activity_co_organizer = self.localize_data(dt["activity_co_organizer"])
|
||||
region = self.localize_data(dt["region"])
|
||||
road_show = self.localize_data(dt["road_show"])
|
||||
tour_details = self.localize_data(dt["tour_details"])
|
||||
award_name = self.localize_data(dt["award_name"])
|
||||
awarding_unit = self.localize_data(dt["awarding_unit"])
|
||||
authors_type = self.localize_data(dt["authors_type"])
|
||||
authors = self.localize_data(dt["authors"])
|
||||
year = (publish_date ? publish_date.strftime("%Y") : "")
|
||||
act = Activity.where(:rss2_id => rss2_id).first
|
||||
act_data = {:rss2_id => rss2_id, :publish_date => publish_date, :updated_at => updated_at, :start_date => start_date, :end_date => end_date, :activity_name_translations => activity_name, :work_title_translations => work_title, :activity_organizer_translations => activity_organizer, :activity_co_organizer_translations => activity_co_organizer, :region_translations => region, :road_show_translations => road_show, :tour_details_translations => tour_details, :award_name_translations => award_name, :awarding_unit_translations => awarding_unit, :authors_type_translations => authors_type, :authors_translations => authors, :year => year, :member_profile => mp}
|
||||
if act.nil?
|
||||
act = Activity.new(act_data)
|
||||
puts "Saving new Activity."
|
||||
else
|
||||
act.update_attributes(act_data)
|
||||
puts "Updating Activity #{act.id}."
|
||||
end
|
||||
exp = Experience.new(:start_date => start_date, :end_date => end_date, :organizationt_title_translations => organization_title, :job_title_translations => job_title, :member_profile => mp)
|
||||
exp.experience_type = type if !type.nil?
|
||||
exp.save
|
||||
puts "Exp created."
|
||||
end
|
||||
end
|
||||
puts "Syncing experiences for #{staff_id} complete."
|
||||
puts "Syncing activities for #{staff_id} complete."
|
||||
puts "*********************************************"
|
||||
end
|
||||
|
||||
|
@ -404,9 +466,9 @@ module FguSyncPlugin
|
|||
puts "Assigning role #{role.key}"
|
||||
case teacher_data["job_status"]
|
||||
when "專任"
|
||||
role_status = role.role_statuses.select{|v| v[:title][:en].upcase == "Full-Time".upcase}.first
|
||||
role_status = role.role_statuses.select{|v| v.title_translations[:en].upcase == "Full-Time".upcase}.first
|
||||
when "兼任"
|
||||
role_status = role.role_statuses.select{|v| v[:title][:en].upcase == "Part-Time".upcase}.first
|
||||
role_status = role.role_statuses.select{|v| v.title_translations[:en].upcase == "Part-Time".upcase}.first
|
||||
else
|
||||
role_status = nil
|
||||
end
|
||||
|
@ -419,7 +481,7 @@ module FguSyncPlugin
|
|||
puts job_title.to_s
|
||||
if job_title.blank?
|
||||
job_title = af.option_list.keys.last.to_i + 1
|
||||
af.option_list[job_title] = {"en" => teacher_data["job_title"], "zh_tw" => teacher_data["job_title"]}
|
||||
af.option_list[job_title] = self.localize_data(teacher_data["job_title"])
|
||||
puts af.option_list.to_s
|
||||
af.save
|
||||
else
|
||||
|
@ -447,7 +509,7 @@ module FguSyncPlugin
|
|||
end
|
||||
end
|
||||
if !av.nil?
|
||||
av.value= {:en => teacher_data["profession_list"], :zh_tw => teacher_data["profession_list"]}
|
||||
av.value= self.localize_data(teacher_data["profession_list"])
|
||||
av.save
|
||||
end
|
||||
#saving courses
|
||||
|
@ -461,14 +523,14 @@ module FguSyncPlugin
|
|||
if !av.nil?
|
||||
course_html = ""
|
||||
if teacher_data["courses"].blank?
|
||||
av.value= {:en => course_html, :zh_tw => course_html}
|
||||
av.value= self.localize_data(course_html)
|
||||
av.save
|
||||
end
|
||||
teacher_data["courses"].each do |course|
|
||||
course_url = course["course_url"]
|
||||
course_url.gsub!(/http:\/\/(.*\.fgu\.edu\.tw)/, 'https://\1')
|
||||
course_html += "<a data-year='#{course["year"].to_i + 1911}' data-sem='#{course["sem"]}' href='#{course_url}' target='_blank'>#{course["course_id"]} #{course["course_name"]}</a><br />"
|
||||
av.value= {:en => course_html, :zh_tw => course_html}
|
||||
av.value = self.localize_data(course_html)
|
||||
av.save
|
||||
end
|
||||
end
|
||||
|
@ -476,8 +538,8 @@ module FguSyncPlugin
|
|||
end
|
||||
mp.email = teacher_data["email"]
|
||||
mp.office_tel = teacher_data["office_tel"]
|
||||
mp.address_translations = {"en" => teacher_data["address"], "zh_tw" => teacher_data["address"]}
|
||||
mp.first_name_translations = {"en" => teacher_data["name"], "zh_tw" => teacher_data["name"]}
|
||||
mp.address_translations = self.localize_data(teacher_data["address"])
|
||||
mp.first_name_translations = self.localize_data(teacher_data["name"])
|
||||
if (!role.nil? && !all_role_ids.include?(role.id))
|
||||
all_role_ids << role.id
|
||||
end
|
||||
|
@ -585,31 +647,59 @@ module FguSyncPlugin
|
|||
"f_empname" => "job_title",
|
||||
"f_emptype" => "emp_type"
|
||||
},
|
||||
'dbo.v_rul_research_create' => {
|
||||
"紀錄編號" => "activity_id",
|
||||
"首次發表時間" => "created_at",
|
||||
"更新日期" => "updated_at",
|
||||
"展演舉行起日" => "activity_start_date",
|
||||
"展演舉行迄日" => "activity_end_date",
|
||||
"展演活動名稱" => "activity_name",
|
||||
"展演作品名稱" => "",
|
||||
"填報系所" => "unit",
|
||||
"填報部門" => "department",
|
||||
"所有作者群" => "authors",
|
||||
"作者類型" => "author_type",
|
||||
"專書類別" => "book_type",
|
||||
"合著者1姓名" => "author1",
|
||||
"合著者2姓名" => "author2",
|
||||
"合著者3姓名" => "author3",
|
||||
"合著者4以上" => "author4",
|
||||
"專書名稱" => "book_title",
|
||||
"使用語文" => "language",
|
||||
"出版社_發表處所名稱" => "publisher",
|
||||
"專書ISBN編號或無" => "isbn",
|
||||
"出版_發表地區" => "location",
|
||||
"備註" => "note"
|
||||
'dbo.v_rul_research_credential' => {
|
||||
"紀錄編號" => "rss2_id",
|
||||
"核發日期" => "issue_date",
|
||||
"證照名稱" => "title",
|
||||
"發照機關" => "issued_by",
|
||||
"證照類別" => "certificate_type",
|
||||
"有效期限" => "expiration_date"
|
||||
},
|
||||
'dbo.v_rul_research_award' => {
|
||||
"紀錄編號" => "rss2_id",
|
||||
"獲獎日期" => "award_date",
|
||||
"獎項名稱" => "award_name",
|
||||
"國別/地區" => "country",
|
||||
"名次" => "ranking",
|
||||
"區域" => "honor_type",
|
||||
"頒發機構名稱" => "awarding_body",
|
||||
"頒獎單位名稱"=> "awarding_unit"
|
||||
},
|
||||
'dbo.v_rul_research_patent' => {
|
||||
"紀錄編號" => "rss2_id",
|
||||
"專利名稱" => "patent_title",
|
||||
"申請國別" => "patent_country",
|
||||
"生效日期"=> "publication_date",
|
||||
"有效期限" => "expiration_date",
|
||||
"專利類型" => "patent_type"
|
||||
},
|
||||
'dbo.v_rul_research_create' => {
|
||||
"紀錄編號" => "rss2_id",
|
||||
"首次發表時間" => "publish_date",
|
||||
"更新日期" => "updated_at",
|
||||
"展演舉行起日" => "start_date",
|
||||
"展演舉行迄日" => "end_date",
|
||||
"展演活動名稱" => "activity_name",
|
||||
"展演作品名稱" => "work_title",
|
||||
"展演主辦單位全銜" => "activity_organizer",
|
||||
"展演協辦單位全銜" => "activity_co_organizer",
|
||||
"展演活動辦理國別/地區" => "region",
|
||||
"是否為巡演" => "road_show",
|
||||
"巡演明細" => "tour_details",
|
||||
"獎名" => "award_name",
|
||||
"頒獎單位" => "awarding_unit",
|
||||
"作者別" => "authors_type",
|
||||
"所有作者群" => "authors"
|
||||
},
|
||||
'dbo.v_rul_research_plan' => {
|
||||
"紀錄編號" => "rss2_id",
|
||||
"計畫名稱" => "project_title",
|
||||
"校外計畫編號" => "project_number",
|
||||
"計畫起日期" => "period_start_date",
|
||||
"計畫迄日期" => "period_end_date",
|
||||
"經費補助單位(補助單位)" => "unit",
|
||||
"所有參與者" => "participants"
|
||||
},
|
||||
"作者別"=>"主要創作者、改編者", "所有作者群"=>"", "簡介"=>"母親節、父親節、重陽敬老節、中秋和新年...任何假期都是陪伴父母家 人的好時節。\r\n圖書館3樓主題展覽區本期展出:「帶著爸媽去旅行」成果特展,歡迎全校師生蒞臨賞析。\r\nhttps://libweb.fgu.edu.tw/zh_tw/News/-展覽-帶著爸媽去旅行-成果特展-歡迎全校師生蒞臨賞析-41046202", "展演主辦單位全銜"=>"未來與樂活產業學系", "展演協辦單位全銜"=>"", "展演活動辦理國別/地區"=>"台灣", "是否為巡演"=>"否", "巡演明細"=>"", "獎名"=>"", "頒獎單位"=>""}
|
||||
'vrul_base' => {
|
||||
"f_email" => "email",
|
||||
"f_phone" => "office_tel",
|
||||
|
@ -632,12 +722,12 @@ module FguSyncPlugin
|
|||
}
|
||||
if key_mapping.has_key?(table_name) && key_mapping[table_name].present?
|
||||
tmp = key_mapping[table_name]
|
||||
mapping_text = tmp.map{|k,v| "#{k} as #{v}"}.join(', ')
|
||||
mapping_text = tmp.map{|k,v| "\"#{k}\" as '#{v}'"}.join(', ')
|
||||
else
|
||||
mapping_text = '*'
|
||||
end
|
||||
if order_fields.nil?
|
||||
sql = "SELECT #{mapping_text} FROM [#{table_name}]"
|
||||
sql = "SELECT #{mapping_text} FROM #{table_name}"
|
||||
field_prefix = ""
|
||||
else # rss_id is the row index
|
||||
if order_fields === false
|
||||
|
@ -822,49 +912,24 @@ module FguSyncPlugin
|
|||
data + data1
|
||||
end
|
||||
|
||||
def self.get_activities(staff_id)
|
||||
result = query_db('dbo.v_rul_research_create', {:f_uni_id=> "F#{staff_id}"})
|
||||
def self.get_certificates(staff_id)
|
||||
result = query_db('dbo.v_rul_research_credential', {"填報者公號"=> "F#{staff_id}"})
|
||||
end
|
||||
# def self.get_projects(staff_id)
|
||||
# # url field not exist in original nccu database
|
||||
# result = query_db('rssproject', {:sta_num=>staff_id})
|
||||
# category_mapping = {
|
||||
# 'Y' => {
|
||||
# 'zh_tw' => '科技部',
|
||||
# 'en' => 'MOST Projects'
|
||||
# },
|
||||
# 'N' => {
|
||||
# 'zh_tw' => '非科技部',
|
||||
# 'en' => 'Other Projects'
|
||||
# }
|
||||
# }
|
||||
# result.each do |h|
|
||||
# h['category'] = category_mapping[h['category']]
|
||||
# end
|
||||
# result
|
||||
# end
|
||||
|
||||
# def self.get_honors(staff_id)
|
||||
# result = query_db('rssreward', {:sta_num=>staff_id})
|
||||
# category_mapping = {
|
||||
# '1' => {
|
||||
# 'zh_tw' => '校內',
|
||||
# 'en' => 'Inside School'
|
||||
# },
|
||||
# '2' => {
|
||||
# 'zh_tw' => '校外',
|
||||
# 'en' => 'Outside School'
|
||||
# },
|
||||
# '3' => {
|
||||
# 'zh_tw' => '事蹟',
|
||||
# 'en' => 'Deeds'
|
||||
# }
|
||||
# }
|
||||
# result.each do |h|
|
||||
# h['category'] = category_mapping[h['category']]
|
||||
# end
|
||||
# result
|
||||
# end
|
||||
def self.get_activities(staff_id)
|
||||
result = query_db('dbo.v_rul_research_create', {"填報者公號"=> "F#{staff_id}"})
|
||||
end
|
||||
def self.get_projects(staff_id)
|
||||
result = query_db('dbo.v_rul_research_plan', {"填報者公號"=> "F#{staff_id}"})
|
||||
end
|
||||
|
||||
def self.get_honors(staff_id)
|
||||
result = query_db('dbo.v_rul_research_award', {"填報者公號"=> "F#{staff_id}"})
|
||||
end
|
||||
|
||||
def self.get_patents(staff_id)
|
||||
result = query_db('dbo.v_rul_research_patent', {"填報者公號"=> "F#{staff_id}"})
|
||||
end
|
||||
|
||||
def self.get_teacher_data(staff_id)
|
||||
data = query_db('vrul_base', {:f_uni_id=> "F#{staff_id}"})
|
||||
|
@ -894,11 +959,12 @@ namespace :sync_nccu_personal_plugins do
|
|||
FguSyncPlugin.sync_books(staff_id,mp)
|
||||
FguSyncPlugin.sync_diplomas(staff_id,mp)
|
||||
FguSyncPlugin.sync_experiences(staff_id,mp)
|
||||
FguSyncPlugin.sync_certificates(staff_id,mp)
|
||||
FguSyncPlugin.sync_honors(staff_id,mp)
|
||||
FguSyncPlugin.sync_patents(staff_id,mp)
|
||||
FguSyncPlugin.sync_projects(staff_id,mp)
|
||||
FguSyncPlugin.sync_activities(staff_id, mp)
|
||||
FguSyncPlugin.sync_fgu_profile(staff_id, mp)
|
||||
# FguSyncPlugin.sync_research_papers(staff_id,mp)
|
||||
# FguSyncPlugin.sync_projects(staff_id,mp)
|
||||
# FguSyncPlugin.sync_honors(staff_id,mp)
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue