Skip to content

Commit d539480

Browse files
committed
code update according to copilot review
1 parent c41af8d commit d539480

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

app/models/publication.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -594,19 +594,19 @@ def check_bibtex_file (bibtex_record)
594594
return false
595595
end
596596

597-
if (['Collection','Conference Paper'].include? self.publication_type.title) && (bibtex_record[:booktitle].blank?)
598-
errors.add(:base, "An #{self.publication_type.title} needs to have a booktitle.")
597+
if (['Collection', 'Conference Paper'].include? self.publication_type.title) && (bibtex_record[:booktitle].blank?)
598+
errors.add(:base, "A #{self.publication_type.title} needs to have a booktitle.")
599599
return false
600600
end
601601

602-
unless ['Booklet','Text','Other','Conference Proceeding'].include? self.publication_type.title
602+
unless ['Booklet', 'Text', 'Other', 'Conference Proceeding'].include? self.publication_type.title
603603
if bibtex_record[:author].nil? && self.editor.nil?
604604
self.errors.add(:base, "You need at least one author or editor for the #{self.publication_type.title}.")
605605
return false
606606
end
607607
end
608608

609-
if publication_type.key == 'bachelorsthesis' || publication_type.key == 'mastersthesis' || publication_type.key == 'phdthesis'
609+
if ['bachelorsthesis', 'mastersthesis', 'phdthesis', 'diplomthesis'].include?(publication_type.key)
610610
if bibtex_record[:school].try(:to_s).nil?
611611
self.errors.add(:base,"A #{self.publication_type.title} needs to have a school.")
612612
return false

app/models/publication_type.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,18 @@ def self.get_publication_type_id(bibtex_record)
4141
publication_key = bibtex_record.to_s[/@(.*?)\{/m, 1].to_s.downcase.strip
4242
datacite_key = BIBTEX_TO_DATACITE_KEY[publication_key] || 'other'
4343
pub_type = PublicationType.find_by(key: datacite_key)
44-
pub_type.id
44+
return pub_type.id if pub_type
45+
other_type = PublicationType.find_by(key: 'other')
46+
other_type&.id
4547
end
4648

47-
type_registry.each_key do |title|
48-
define_singleton_method(title.gsub(/\s+/, '')) do
49-
find_by(key: type_registry[title]['key'])
49+
begin
50+
type_registry.each_key do |title|
51+
define_singleton_method(title.gsub(/\s+/, '')) do
52+
find_by(key: type_registry[title]['key'])
53+
end
5054
end
55+
rescue => e
56+
Rails.logger.error("Failed to load publication types: #{e.message}")
5157
end
5258
end

db/seeds/005_publication_types.seeds.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@
4444
# -------------------------------------------------------------------
4545
# STEP 2 — Ensure all DataCite YAML types exist and match
4646
# -------------------------------------------------------------------
47+
existing_by_key = PublicationType.all.index_by(&:key)
4748
expected.values.each do |etype|
4849
title = etype["title"]
4950
key = etype["key"]
50-
51-
existing = PublicationType.find_by(key: key)
51+
existing = existing_by_key[key]
5252

5353
if existing.nil?
5454
puts "Creating new type: #{title}"

test/functional/publications_controller_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,9 @@ def test_title
300300
assert_difference('Publication.count', 0) do
301301
post :create, params: { subaction: 'ImportMultiple', publication: { bibtex_file: fixture_file_upload('bibtex/error_bibtex.bib'), project_ids: [projects(:one).id] } }
302302
assert_redirected_to publications_path
303-
assert_includes flash[:error], 'An Conference Paper needs to have a booktitle.'
303+
assert_includes flash[:error], 'A Conference Paper needs to have a booktitle.'
304304
assert_includes flash[:error], 'Please check your bibtex files, each publication should contain a title or a chapter name.'
305-
assert_includes flash[:error], 'An Collection needs to have a booktitle.'
305+
assert_includes flash[:error], 'A Collection needs to have a booktitle.'
306306
assert_includes flash[:error], 'A Doctoral Thesis needs to have a school.'
307307
assert_includes flash[:error], "A Master's Thesis needs to have a school."
308308
assert_includes flash[:error], 'You need at least one author or editor for the Journal Article.'

0 commit comments

Comments
 (0)