fix error

This commit is contained in:
邱博亞 2021-12-29 15:08:13 +08:00
parent 1f0064173c
commit 5e603416ea
1 changed files with 53 additions and 31 deletions

View File

@ -49,8 +49,10 @@ module AsiaSyncPlugin
def self.sync_journal_papers(query_result, user)
puts "Journal Paper for user: #{user.user_name}"
journal_papers = query_result["journal"].to_a
if !query_result['emp'].blank?
JournalPaper.where(member_profile_id: user.member_profile_id,:rss2_id=>nil).destroy
end
return if journal_papers.count == 0
#JournalPaper.where(member_profile_id: user.member_profile_id,:rss2_id=>nil).destroy
journal_papers.each do |journal_paper|
jp = JournalPaper.where(:rss2_id=> journal_paper["ukey"]).first
jp = JournalPaper.new if jp.nil?
@ -73,8 +75,10 @@ module AsiaSyncPlugin
def self.sync_conference_papers(query_result, user)
puts "Conference Paper for user: #{user.user_name}"
conference_papers = query_result["conference"].to_a
if !query_result['emp'].blank?
WritingConference.where(member_profile_id: user.member_profile_id,:rss2_id=>nil).destroy
end
return if conference_papers.count == 0
#WritingConference.where(member_profile_id: user.member_profile_id,:rss2_id=>nil).destroy
conference_papers.each do |conference_paper|
wc = WritingConference.where(:rss2_id=> conference_paper["ukey"]).first
wc = WritingConference.new if wc.nil?
@ -94,8 +98,10 @@ module AsiaSyncPlugin
def self.sync_projects(query_result, user)
puts "Projects(Research Grants) for user: #{user.user_name}"
projects = query_result["research"].to_a
if !query_result['emp'].blank?
Project.where(member_profile_id: user.member_profile_id,:rss2_id=>nil).destroy
end
return if projects.count == 0
#Project.where(member_profile_id: user.member_profile_id,:rss2_id=>nil).destroy
projects.each do |project|
pj = Project.where(:rss2_id=> project["ukey"]).first
pj = Project.new if pj.nil?
@ -118,8 +124,10 @@ module AsiaSyncPlugin
puts "books for user: #{user.user_name}"
books = query_result["books"].to_a
books1 = query_result["books1"].to_a
if !query_result['emp'].blank?
Book.where(member_profile_id: user.member_profile_id,:rss2_id=>nil).destroy
end
return if (books.count == 0 && books1.count == 0)
#Book.where(member_profile_id: user.member_profile_id,:rss2_id=>nil).destroy
books.each do |book|
bk = Book.where(:rss2_id=> book["ukey"]).first
bk = Book.new if bk.nil?
@ -159,8 +167,10 @@ module AsiaSyncPlugin
def self.sync_patents(query_result, user)
puts "Patents for user: #{user.user_name}"
patents = query_result["patent"].to_a
if !query_result['emp'].blank?
Patent.where(member_profile_id: user.member_profile_id,:rss2_id=>nil).destroy
end
return if (patents.count == 0 )
#Patent.where(member_profile_id: user.member_profile_id,:rss2_id=>nil).destroy
patents.each do |patent|
pt = Patent.where(:rss2_id=> patent["ukey"]).first
pt = Patent.new if pt.nil?
@ -183,8 +193,10 @@ module AsiaSyncPlugin
def self.sync_honors(query_result, user)
puts "Honors(Awards) for user: #{user.user_name}"
honors = query_result["award"].to_a
if !query_result['emp'].blank?
Honor.where(member_profile_id: user.member_profile_id,:rss2_id=>nil).destroy
end
return if (honors.count == 0 )
#Honor.where(member_profile_id: user.member_profile_id,:rss2_id=>nil).destroy
honors.each do |honor|
hn = Honor.where(:rss2_id=> honor["ukey"]).first
hn = Honor.new if hn.nil?
@ -200,8 +212,10 @@ module AsiaSyncPlugin
def self.sync_activities(query_result, user)
puts "Activities(Shows) for user: #{user.user_name}"
activities = query_result["show"].to_a
if !query_result['emp'].blank?
Activity.where(member_profile_id: user.member_profile_id,:rss2_id=>nil).destroy
end
return if (activities.count == 0 )
#Activity.where(member_profile_id: user.member_profile_id,:rss2_id=>nil).destroy
activities.each do |activity|
act = Activity.where(:rss2_id=> activity["ukey"]).first
act = Activity.new if act.nil?
@ -221,8 +235,10 @@ module AsiaSyncPlugin
def self.sync_courses(query_result, user)
puts "Courses(Course Information) for user: #{user.user_name}"
courses = query_result["cos_data"].to_a
if !query_result['emp'].blank?
Course.where(member_profile_id: user.member_profile_id,:rss2_id=>nil).destroy
end
return if (courses.count == 0 )
#Course.where(member_profile_id: user.member_profile_id,:rss2_id=>nil).destroy
courses.each do |course|
cs = Course.where(:rss2_id=> course["ukey"]).first
cs = Course.new if cs.nil?
@ -236,21 +252,20 @@ module AsiaSyncPlugin
course_category = CourseCategory.create(:title_translations=>localize_data(course_class))
end
cs.course_category = course_category
end
course_year_semester = course["cos_data_nm"].split(/[【】]/)[1].strip rescue "" #學年度和學期 ex: 第109學年第2學期A班
if !course_year_semester.blank?
year = course_year_semester.split(/[第學]/)[1].strip rescue nil
cs.year = year
course_semester_title = course_year_semester.split(/[年:]/)[1].strip rescue ""
if !course_semester_title.blank?
course_semester = CourseSemester.where(:title=>course_semester_title).first
if course_semester.nil?
course_semester = CourseSemester.create(:title_translations=>localize_data(course_semester_title))
end
cs.course_semester = course_semester
end
end
end
course_year_semester = course["cos_data_nm"].split(/[【】]/)[1].strip rescue "" #學年度和學期 ex: 第109學年第2學期A班
if !course_year_semester.blank?
year = course_year_semester.split(/[第學]/)[1].strip rescue nil
cs.year = year
course_semester_title = course_year_semester.split(/[年:]/)[1].strip rescue ""
if !course_semester_title.blank?
course_semester = CourseSemester.where(:title=>course_semester_title).first
if course_semester.nil?
course_semester = CourseSemester.create(:title_translations=>localize_data(course_semester_title))
end
cs.course_semester = course_semester
end
end
cs.course_code = course["cos_data"] #課程代碼 ex: "ES200023A"
cs.member_profile_id = user.member_profile_id
@ -261,8 +276,10 @@ module AsiaSyncPlugin
def self.sync_researches(query_result, user)
puts "Researches(Thesis Advisor) for user: #{user.user_name}"
researches = query_result["paper_data"].to_a
if !query_result['emp'].blank?
Research.where(member_profile_id: user.member_profile_id,:rss2_id=>nil).destroy
end
return if (researches.count == 0 )
#Research.where(member_profile_id: user.member_profile_id,:rss2_id=>nil).destroy
researches.each do |research|
rs = Research.where(:rss2_id=> research["ukey"]).first
rs = Research.new if rs.nil?
@ -281,8 +298,10 @@ module AsiaSyncPlugin
def self.sync_create_designs(query_result, user)
puts "Create Designs for user: #{user.user_name}"
create_designs = query_result["create"].to_a
if !query_result['emp'].blank?
CreateDesign.where(member_profile_id: user.member_profile_id,:rss2_id=>nil).destroy
end
return if (create_designs.count == 0 )
#CreateDesign.where(member_profile_id: user.member_profile_id,:rss2_id=>nil).destroy
create_designs.each do |create_design|
cd = CreateDesign.where(:rss2_id=> create_design["ukey"]).first
cd = CreateDesign.new if cd.nil?
@ -298,8 +317,10 @@ module AsiaSyncPlugin
def self.sync_tec_transfers(query_result, user)
puts "Technology Transfers for user: #{user.user_name}"
tec_transfers = query_result["tec_transfer"].to_a
if !query_result['emp'].blank?
TecTransfer.where(member_profile_id: user.member_profile_id,:rss2_id=>nil).destroy
end
return if (tec_transfers.count == 0 )
#TecTransfer.where(member_profile_id: user.member_profile_id,:rss2_id=>nil).destroy
tec_transfers.each do |tec_transfer|
tt = TecTransfer.where(:rss2_id=> tec_transfer["ukey"]).first
tt = TecTransfer.new if tt.nil?
@ -320,8 +341,10 @@ module AsiaSyncPlugin
def self.sync_college_projects(query_result, user)
puts "College Projects for user: #{user.user_name}"
college_projects = query_result["college_data"].to_a
if !query_result['emp'].blank?
CollegeProject.where(member_profile_id: user.member_profile_id,:rss2_id=>nil).destroy
end
return if (college_projects.count == 0 )
#CollegeProject.where(member_profile_id: user.member_profile_id,:rss2_id=>nil).destroy
college_projects.each do |college_project|
cp = CollegeProject.where(:rss2_id=> college_project["ukey"]).first
cp = CollegeProject.new if cp.nil?
@ -373,15 +396,14 @@ namespace :sync_asia_personal_plugins do
res
end
def get_sync_data(user_id)
uri = URI.parse("https://webap.asia.edu.tw/cfd2020/API/Research/Load")
uri = URI.parse("https://webap.asia.edu.tw/TchEportfolio/API/Research/Load")
@read_timeout = 300
data = "id=#{user_id}"
cipher = OpenSSL::Cipher::Cipher.new("des").encrypt.tap do |obj|
cipher = OpenSSL::Cipher::Cipher.new("des-cbc").encrypt.tap do |obj|
obj.iv = AsiaSyncPlugin::IV
obj.key = AsiaSyncPlugin::KEY
end
cipher.update(data)
encrypt = cipher.final()
encrypt = cipher.update(data) + cipher.final()
encrypt_base64 = Base64.encode64(encrypt).strip
res = net_http_get_response(uri + "?#{encrypt_base64}")
return JSON.parse(res.body,{object_class: AsiaSyncPlugin::SafeHash})