From 14f56a1e6185ae7d6f2c609585d7aedf175eb591 Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Mon, 19 Jan 2015 15:58:05 +0000 Subject: [PATCH 01/65] Fixed parent assignment and taxonomic data --- app/models/nomenclature_change/status_to_accepted.rb | 4 ++-- app/models/taxon_concept_observer.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/nomenclature_change/status_to_accepted.rb b/app/models/nomenclature_change/status_to_accepted.rb index 18961dba6f..451a1ea9f7 100644 --- a/app/models/nomenclature_change/status_to_accepted.rb +++ b/app/models/nomenclature_change/status_to_accepted.rb @@ -16,7 +16,7 @@ class NomenclatureChange::StatusToAccepted < NomenclatureChange include NomenclatureChange::StatusChangeHelpers build_steps( - :primary_output, :parent, :receive, :notes, :legislation, :summary + :primary_output, :parent, :notes, :legislation, :summary ) validates :status, inclusion: { in: self.status_dict, @@ -36,7 +36,7 @@ def set_output_rank_id end def set_output_parent_id - return true unless needs_to_set_parent? + return true unless needs_to_set_parent? && primary_output.new_parent_id.nil? primary_output && primary_output.taxon_concept && primary_output.new_parent_id = primary_output.taxon_concept.parent_id end diff --git a/app/models/taxon_concept_observer.rb b/app/models/taxon_concept_observer.rb index 81dab35bf0..b590c4f4dd 100644 --- a/app/models/taxon_concept_observer.rb +++ b/app/models/taxon_concept_observer.rb @@ -4,7 +4,7 @@ class TaxonConceptObserver < ActiveRecord::Observer def before_validation(taxon_concept) data = taxon_concept.data || {} data['rank_name'] = taxon_concept.rank && taxon_concept.rank.name - if taxon_concept.new_record? && taxon_concept.parent + if taxon_concept.parent data = data.merge taxon_concept.parent.data.slice( 'kingdom_id', 'kingdom_name', 'phylum_id', 'phylum_name', 'class_id', 'class_name', 'order_id', 'order_name', 'family_id', 'family_name', From 596ee1a74a250801a817d08e745de9753ebd0532 Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Tue, 20 Jan 2015 12:21:31 +0000 Subject: [PATCH 02/65] Added default parent and compatible validation for T->A --- app/helpers/admin/nomenclature_changes_helper.rb | 12 ++++++++++++ app/models/nomenclature_change/status_to_accepted.rb | 11 +++++++++++ .../status_to_accepted/parent.html.erb | 7 ++++--- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/app/helpers/admin/nomenclature_changes_helper.rb b/app/helpers/admin/nomenclature_changes_helper.rb index 038db2ed41..eb18a5acf6 100644 --- a/app/helpers/admin/nomenclature_changes_helper.rb +++ b/app/helpers/admin/nomenclature_changes_helper.rb @@ -320,4 +320,16 @@ def name_reassignment_label(reassignment) end end + def default_parent(primary_output) + output = primary_output.object + rank = output.rank_id + name = output.taxon_concept.full_name + if output.name_status == 'T' && rank > 7 + TaxonConcept.where("rank_id = ? AND '" + name + "' LIKE '%' || full_name || '%'", + rank-1).first + else + output.new_parent + end + end + end diff --git a/app/models/nomenclature_change/status_to_accepted.rb b/app/models/nomenclature_change/status_to_accepted.rb index 451a1ea9f7..e957e88b6e 100644 --- a/app/models/nomenclature_change/status_to_accepted.rb +++ b/app/models/nomenclature_change/status_to_accepted.rb @@ -22,6 +22,7 @@ class NomenclatureChange::StatusToAccepted < NomenclatureChange in: self.status_dict, message: "%{value} is not a valid status" } + validate :compatible_parent, if: :parent? before_validation :set_output_name_status, if: :primary_output_or_submitting? before_validation :set_output_rank_id, if: :primary_output_or_submitting? before_validation :set_output_parent_id, if: :primary_output_or_submitting? @@ -69,4 +70,14 @@ def build_auto_reassignments true end + def compatible_parent + parent = primary_output.new_parent + tc = primary_output.taxon_concept + unless parent.rank_id == tc.rank_id-1 && tc.full_name.include?(parent.full_name) + errors.add(:primary_output, "Must have a compatible parent") + return false + end + return true + end + end diff --git a/app/views/admin/nomenclature_changes/status_to_accepted/parent.html.erb b/app/views/admin/nomenclature_changes/status_to_accepted/parent.html.erb index 3fc4aaee13..7f38d5c7f8 100644 --- a/app/views/admin/nomenclature_changes/status_to_accepted/parent.html.erb +++ b/app/views/admin/nomenclature_changes/status_to_accepted/parent.html.erb @@ -8,10 +8,11 @@ <%= ff.text_field :new_parent_id, { :class => 'taxon-concept', - :'data-name' => ff.object.new_parent.try(:full_name), - :'data-name-status' => ff.object.new_parent.try(:name_status), + :'data-name' => default_parent(ff).try(:full_name), + :'data-name-status' => default_parent(ff).try(:name_status).to_s, :'data-name-status-filter' => ['A'].to_json, - :'data-taxonomy-id' => @taxonomy.id + :'data-taxonomy-id' => @taxonomy.id, + :'value' => default_parent(ff).try(:id) } %> From 8eb9437247fc626cafc4136e1265e3da33fd4d1c Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Tue, 20 Jan 2015 13:32:24 +0000 Subject: [PATCH 03/65] Fixed tests due to recieve step deletion --- .../status_to_accepted_controller_spec.rb | 9 --------- .../shared/status_change_definitions.rb | 2 +- .../status_to_accepted/processor_spec.rb | 4 ++-- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/spec/controllers/admin/nomenclature_changes/status_to_accepted_controller_spec.rb b/spec/controllers/admin/nomenclature_changes/status_to_accepted_controller_spec.rb index 7929f3c5b3..f4128feb6b 100644 --- a/spec/controllers/admin/nomenclature_changes/status_to_accepted_controller_spec.rb +++ b/spec/controllers/admin/nomenclature_changes/status_to_accepted_controller_spec.rb @@ -14,15 +14,6 @@ response.should render_template('primary_output') end end - context :receive do - before(:each) do - @status_change = s_to_a_with_primary_output - end - it 'renders the receive template' do - get :show, id: :receive, nomenclature_change_id: @status_change.id - response.should render_template('receive') - end - end context :notes do before(:each) do @status_change = s_to_a_with_primary_output diff --git a/spec/models/nomenclature_change/shared/status_change_definitions.rb b/spec/models/nomenclature_change/shared/status_change_definitions.rb index 15cb64266b..f7ba0e9d08 100644 --- a/spec/models/nomenclature_change/shared/status_change_definitions.rb +++ b/spec/models/nomenclature_change/shared/status_change_definitions.rb @@ -92,7 +92,7 @@ new_name_status: 'A' }, input_attributes: { taxon_concept_id: input_species.id }, - status: NomenclatureChange::StatusToAccepted::RECEIVE + status: NomenclatureChange::StatusToAccepted::LEGISLATION ).reload } let(:s_to_a_with_swap){ diff --git a/spec/models/nomenclature_change/status_to_accepted/processor_spec.rb b/spec/models/nomenclature_change/status_to_accepted/processor_spec.rb index 2c03bf1147..1d6f5bfb59 100644 --- a/spec/models/nomenclature_change/status_to_accepted/processor_spec.rb +++ b/spec/models/nomenclature_change/status_to_accepted/processor_spec.rb @@ -41,7 +41,7 @@ new_name_status: 'A' }, input_attributes: { taxon_concept_id: input_species.id }, - status: NomenclatureChange::StatusToAccepted::RECEIVE + status: NomenclatureChange::StatusToAccepted::LEGISLATION ).reload } let(:status_change){ s_to_a_with_input } @@ -68,7 +68,7 @@ new_name_status: 'A' }, input_attributes: { taxon_concept_id: input_species.id }, - status: NomenclatureChange::StatusToAccepted::RECEIVE + status: NomenclatureChange::StatusToAccepted::LEGISLATION ).reload } let(:status_change){ s_to_a_with_input } From d8803623367370041e69bd7578ac6d77cb28d61b Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Tue, 20 Jan 2015 14:21:05 +0000 Subject: [PATCH 04/65] Removed public notes step from status changes --- app/models/nomenclature_change/status_change_helpers.rb | 2 +- app/models/nomenclature_change/status_swap.rb | 2 +- app/models/nomenclature_change/status_to_accepted.rb | 2 +- app/models/nomenclature_change/status_to_synonym.rb | 2 +- .../nomenclature_changes/status_swap_controller_spec.rb | 9 --------- .../status_to_accepted_controller_spec.rb | 9 --------- .../status_to_synonym_controller_spec.rb | 9 --------- 7 files changed, 4 insertions(+), 31 deletions(-) diff --git a/app/models/nomenclature_change/status_change_helpers.rb b/app/models/nomenclature_change/status_change_helpers.rb index 3e83bd263d..3164822b70 100644 --- a/app/models/nomenclature_change/status_change_helpers.rb +++ b/app/models/nomenclature_change/status_change_helpers.rb @@ -25,7 +25,7 @@ def self.included(base) validate :required_primary_output, if: :primary_output_or_submitting? - before_save :build_auto_reassignments, if: :notes? + before_save :build_auto_reassignments, if: :summary? end end diff --git a/app/models/nomenclature_change/status_swap.rb b/app/models/nomenclature_change/status_swap.rb index d4e7993cf3..feaff45764 100644 --- a/app/models/nomenclature_change/status_swap.rb +++ b/app/models/nomenclature_change/status_swap.rb @@ -22,7 +22,7 @@ class NomenclatureChange::StatusSwap < NomenclatureChange include NomenclatureChange::StatusChangeHelpers build_steps( - :primary_output, :swap, :notes, :legislation, :summary + :primary_output, :swap, :legislation, :summary ) validates :status, inclusion: { in: self.status_dict, diff --git a/app/models/nomenclature_change/status_to_accepted.rb b/app/models/nomenclature_change/status_to_accepted.rb index e957e88b6e..3b19ae2180 100644 --- a/app/models/nomenclature_change/status_to_accepted.rb +++ b/app/models/nomenclature_change/status_to_accepted.rb @@ -16,7 +16,7 @@ class NomenclatureChange::StatusToAccepted < NomenclatureChange include NomenclatureChange::StatusChangeHelpers build_steps( - :primary_output, :parent, :notes, :legislation, :summary + :primary_output, :parent, :legislation, :summary ) validates :status, inclusion: { in: self.status_dict, diff --git a/app/models/nomenclature_change/status_to_synonym.rb b/app/models/nomenclature_change/status_to_synonym.rb index cba0d5c9a0..2a44ec978e 100644 --- a/app/models/nomenclature_change/status_to_synonym.rb +++ b/app/models/nomenclature_change/status_to_synonym.rb @@ -22,7 +22,7 @@ class NomenclatureChange::StatusToSynonym < NomenclatureChange include NomenclatureChange::StatusChangeHelpers build_steps( - :primary_output, :relay, :accepted_name, :notes, :legislation, :summary + :primary_output, :relay, :accepted_name, :legislation, :summary ) validates :status, inclusion: { in: self.status_dict, diff --git a/spec/controllers/admin/nomenclature_changes/status_swap_controller_spec.rb b/spec/controllers/admin/nomenclature_changes/status_swap_controller_spec.rb index f5a90620a0..67a2248e8e 100644 --- a/spec/controllers/admin/nomenclature_changes/status_swap_controller_spec.rb +++ b/spec/controllers/admin/nomenclature_changes/status_swap_controller_spec.rb @@ -23,15 +23,6 @@ response.should render_template('swap') end end - context :notes do - before(:each) do - @status_change = s_to_a_with_swap - end - it 'renders the notes template' do - get :show, id: :notes, nomenclature_change_id: @status_change.id - response.should render_template('notes') - end - end context :reassignments do before(:each) do @status_change = s_to_a_with_swap diff --git a/spec/controllers/admin/nomenclature_changes/status_to_accepted_controller_spec.rb b/spec/controllers/admin/nomenclature_changes/status_to_accepted_controller_spec.rb index f4128feb6b..866ebb9511 100644 --- a/spec/controllers/admin/nomenclature_changes/status_to_accepted_controller_spec.rb +++ b/spec/controllers/admin/nomenclature_changes/status_to_accepted_controller_spec.rb @@ -14,15 +14,6 @@ response.should render_template('primary_output') end end - context :notes do - before(:each) do - @status_change = s_to_a_with_primary_output - end - it 'renders the notes template' do - get :show, id: :notes, nomenclature_change_id: @status_change.id - response.should render_template('notes') - end - end context :reassignments do before(:each) do @status_change = s_to_a_with_input diff --git a/spec/controllers/admin/nomenclature_changes/status_to_synonym_controller_spec.rb b/spec/controllers/admin/nomenclature_changes/status_to_synonym_controller_spec.rb index e3f852bced..b3301c6579 100644 --- a/spec/controllers/admin/nomenclature_changes/status_to_synonym_controller_spec.rb +++ b/spec/controllers/admin/nomenclature_changes/status_to_synonym_controller_spec.rb @@ -23,15 +23,6 @@ response.should render_template('relay') end end - context :notes do - before(:each) do - @status_change = a_to_s_with_primary_output - end - it 'renders the notes template' do - get :show, id: :notes, nomenclature_change_id: @status_change.id - response.should render_template('notes') - end - end context :reassignments do before(:each) do @status_change = a_to_s_with_input_and_secondary_output From 4eb40164fae9193400689e321ae277ac32f38fcc Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Tue, 20 Jan 2015 16:27:06 +0000 Subject: [PATCH 05/65] Methodes moved and code improved --- .../admin/nomenclature_changes_helper.rb | 12 -------- app/models/nomenclature_change/output.rb | 29 +++++++++++++++++++ .../nomenclature_change/status_to_accepted.rb | 11 ------- app/models/rank.rb | 5 ++++ .../status_to_accepted/parent.html.erb | 6 ++-- 5 files changed, 37 insertions(+), 26 deletions(-) diff --git a/app/helpers/admin/nomenclature_changes_helper.rb b/app/helpers/admin/nomenclature_changes_helper.rb index eb18a5acf6..038db2ed41 100644 --- a/app/helpers/admin/nomenclature_changes_helper.rb +++ b/app/helpers/admin/nomenclature_changes_helper.rb @@ -320,16 +320,4 @@ def name_reassignment_label(reassignment) end end - def default_parent(primary_output) - output = primary_output.object - rank = output.rank_id - name = output.taxon_concept.full_name - if output.name_status == 'T' && rank > 7 - TaxonConcept.where("rank_id = ? AND '" + name + "' LIKE '%' || full_name || '%'", - rank-1).first - else - output.new_parent - end - end - end diff --git a/app/models/nomenclature_change/output.rb b/app/models/nomenclature_change/output.rb index ef5bdbfe58..41027a5403 100644 --- a/app/models/nomenclature_change/output.rb +++ b/app/models/nomenclature_change/output.rb @@ -75,6 +75,7 @@ class NomenclatureChange::Output < ActiveRecord::Base :if => Proc.new { |c| c.taxon_concept_id.blank? } validate :validate_tmp_taxon_concept, :if => Proc.new { |c| c.will_create_taxon? || c.will_update_taxon? } + validate :compatible_parent?, if: Proc.new { |c| c.parent_status?} before_validation :populate_taxon_concept_fields, :if => Proc.new { |c| (c.new_record? || c.taxon_concept_id_changed?) && c.taxon_concept } @@ -172,6 +173,34 @@ def taxon_name_already_existing? return !TaxonConcept.where("lower(full_name) = ?", display_full_name.downcase).empty? end + def parent_status? + !nomenclature_change.nil? && nomenclature_change.status == "parent" + end + + def compatible_parent? + unless new_parent.rank.name == rank.parent_rank && + taxon_concept.full_name.include?(new_parent.full_name) && new_parent.name_status == 'A' && + taxonomy_id = Taxonomy.find_by_name(Taxonomy::CITES_EU).id + errors.add('', "must have a compatible parent") + return false + end + return true + end + + def default_parent + name = taxon_concept.full_name + if name_status == 'T' && + Rank.in_range(Rank::VARIETY, Rank::SPECIES).include?(rank.name) + + taxonomy_id = Taxonomy.find_by_name(Taxonomy::CITES_EU).id + TaxonConcept.where("data->'rank_name' = ? AND UPPER(full_name) = UPPER(?) AND + taxonomy_id = ? AND name_status = 'A'", + rank.parent_rank, name.split.first, taxonomy_id).first + else + new_parent + end + end + def reassignables_by_class(reassignable_type) reassignable_type.constantize.where( :taxon_concept_id => taxon_concept.id diff --git a/app/models/nomenclature_change/status_to_accepted.rb b/app/models/nomenclature_change/status_to_accepted.rb index 3b19ae2180..33645ba93e 100644 --- a/app/models/nomenclature_change/status_to_accepted.rb +++ b/app/models/nomenclature_change/status_to_accepted.rb @@ -22,7 +22,6 @@ class NomenclatureChange::StatusToAccepted < NomenclatureChange in: self.status_dict, message: "%{value} is not a valid status" } - validate :compatible_parent, if: :parent? before_validation :set_output_name_status, if: :primary_output_or_submitting? before_validation :set_output_rank_id, if: :primary_output_or_submitting? before_validation :set_output_parent_id, if: :primary_output_or_submitting? @@ -70,14 +69,4 @@ def build_auto_reassignments true end - def compatible_parent - parent = primary_output.new_parent - tc = primary_output.taxon_concept - unless parent.rank_id == tc.rank_id-1 && tc.full_name.include?(parent.full_name) - errors.add(:primary_output, "Must have a compatible parent") - return false - end - return true - end - end diff --git a/app/models/rank.rb b/app/models/rank.rb index b9528d46a3..acdd1fba55 100644 --- a/app/models/rank.rb +++ b/app/models/rank.rb @@ -48,6 +48,11 @@ def self.in_range(lower_rank, higher_rank) dict[higher_rank_idx..lower_rank_idx] end + def parent_rank + rank_index = self.class.dict.index(name) + self.class.dict[rank_index-1] + end + private def dependent_objects_map diff --git a/app/views/admin/nomenclature_changes/status_to_accepted/parent.html.erb b/app/views/admin/nomenclature_changes/status_to_accepted/parent.html.erb index 7f38d5c7f8..f2fcb4b634 100644 --- a/app/views/admin/nomenclature_changes/status_to_accepted/parent.html.erb +++ b/app/views/admin/nomenclature_changes/status_to_accepted/parent.html.erb @@ -8,11 +8,11 @@ <%= ff.text_field :new_parent_id, { :class => 'taxon-concept', - :'data-name' => default_parent(ff).try(:full_name), - :'data-name-status' => default_parent(ff).try(:name_status).to_s, + :'data-name' => ff.object.default_parent.try(:full_name), + :'data-name-status' => ff.object.default_parent.try(:name_status).to_s, :'data-name-status-filter' => ['A'].to_json, :'data-taxonomy-id' => @taxonomy.id, - :'value' => default_parent(ff).try(:id) + :'value' => ff.object.default_parent.try(:id) } %> From 798048e5c90da66275a834fc2c482a71e1588d7f Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Wed, 21 Jan 2015 06:49:07 +0000 Subject: [PATCH 06/65] fixed parent rank name to handle infra ranks correctly --- app/models/nomenclature_change/output.rb | 4 ++-- app/models/rank.rb | 12 +++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/models/nomenclature_change/output.rb b/app/models/nomenclature_change/output.rb index 41027a5403..8e76414c94 100644 --- a/app/models/nomenclature_change/output.rb +++ b/app/models/nomenclature_change/output.rb @@ -178,7 +178,7 @@ def parent_status? end def compatible_parent? - unless new_parent.rank.name == rank.parent_rank && + unless new_parent.rank.name == rank.parent_rank_name && taxon_concept.full_name.include?(new_parent.full_name) && new_parent.name_status == 'A' && taxonomy_id = Taxonomy.find_by_name(Taxonomy::CITES_EU).id errors.add('', "must have a compatible parent") @@ -195,7 +195,7 @@ def default_parent taxonomy_id = Taxonomy.find_by_name(Taxonomy::CITES_EU).id TaxonConcept.where("data->'rank_name' = ? AND UPPER(full_name) = UPPER(?) AND taxonomy_id = ? AND name_status = 'A'", - rank.parent_rank, name.split.first, taxonomy_id).first + rank.parent_rank_name, name.split.first, taxonomy_id).first else new_parent end diff --git a/app/models/rank.rb b/app/models/rank.rb index acdd1fba55..b9d08ff166 100644 --- a/app/models/rank.rb +++ b/app/models/rank.rb @@ -48,9 +48,15 @@ def self.in_range(lower_rank, higher_rank) dict[higher_rank_idx..lower_rank_idx] end - def parent_rank - rank_index = self.class.dict.index(name) - self.class.dict[rank_index-1] + def parent_rank_name + if [Rank::SUBSPECIES, Rank::VARIETY].include?(name) + Rank::SPECIES + elsif name != Rank::KINGDOM + rank_index = self.class.dict.index(name) + self.class.dict[rank_index-1] + else + nil + end end private From 0b191efb0f485b9a5c808212726e16d9e5140811 Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Wed, 21 Jan 2015 08:54:55 +0000 Subject: [PATCH 07/65] fixed summary of parent change when parent previously not in place --- .../nomenclature_change/output_taxon_concept_processor.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/nomenclature_change/output_taxon_concept_processor.rb b/app/models/nomenclature_change/output_taxon_concept_processor.rb index cb0c575cf1..011cae4149 100644 --- a/app/models/nomenclature_change/output_taxon_concept_processor.rb +++ b/app/models/nomenclature_change/output_taxon_concept_processor.rb @@ -40,7 +40,11 @@ def summary res << "#{@output.taxon_concept.full_name} rank changed from #{@output.taxon_concept.rank.name} to #{@output.new_rank.name}" end if @output.new_parent - res << "#{@output.taxon_concept.full_name} parent changed from #{@output.taxon_concept.parent.try(:full_name)} to #{@output.new_parent.full_name}" + res << if @output.taxon_concept.parent + "#{@output.taxon_concept.full_name} parent changed from #{@output.taxon_concept.parent.full_name} to #{@output.new_parent.full_name}" + else + "#{@output.taxon_concept.full_name} parent set to #{@output.new_parent.full_name}" + end end if @output.new_name_status.present? res << "#{@output.taxon_concept.full_name} name status changed from #{@output.taxon_concept.name_status} to #{@output.new_name_status}" From 615969b9670ca38a00f8d3bf3e9303b7b4b1c758 Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Wed, 21 Jan 2015 08:55:59 +0000 Subject: [PATCH 08/65] moved expected_full_name method to TaxonConcept --- .../taxonomic_tree_name_resolver.rb | 20 ++++--------------- app/models/taxon_concept.rb | 13 ++++++++++++ 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/app/models/nomenclature_change/taxonomic_tree_name_resolver.rb b/app/models/nomenclature_change/taxonomic_tree_name_resolver.rb index 2dff9bbac2..cb8aeb8780 100644 --- a/app/models/nomenclature_change/taxonomic_tree_name_resolver.rb +++ b/app/models/nomenclature_change/taxonomic_tree_name_resolver.rb @@ -12,11 +12,12 @@ def process private def resolve(node) - Rails.logger.debug("Resolving node name: #{node.full_name} (expected: #{expected_name(node)})") + expected_full_name = node.expected_full_name(node.parent) + Rails.logger.debug("Resolving node name: #{node.full_name} (expected: #{expected_full_name})") unless name_compatible_with_parent?(node) compatible_node_attributes = { taxonomy_id: node.taxonomy_id, - full_name: expected_name(node) + full_name: expected_full_name } # find or create a new accepted name compatible with this parent compatible_node = TaxonConcept.where(compatible_node_attributes).first @@ -52,20 +53,7 @@ def resolve(node) end def name_compatible_with_parent?(node) - expected_name(node) == node.full_name - end - - def expected_name(node) - if node.rank && - Rank.in_range(Rank::VARIETY, Rank::SPECIES).include?(node.rank.name) - node.parent.full_name + if node.rank.name == Rank::VARIETY - ' var. ' - else - ' ' - end + node.taxon_name.try(:scientific_name).try(:downcase) - else - node.full_name - end + node.expected_full_name(node.parent) == node.full_name end end diff --git a/app/models/taxon_concept.rb b/app/models/taxon_concept.rb index 32222f548e..7bbed616be 100644 --- a/app/models/taxon_concept.rb +++ b/app/models/taxon_concept.rb @@ -291,6 +291,19 @@ def inherited_standard_taxon_concept_references standard_taxon_concept_references.keep_if{ |ref| !ref_ids.include? ref.id } end + def expected_full_name(parent) + if self.rank && + Rank.in_range(Rank::VARIETY, Rank::SPECIES).include?(self.rank.name) + parent.full_name + if self.rank.name == Rank::VARIETY + ' var. ' + else + ' ' + end + self.taxon_name.try(:scientific_name).try(:downcase) + else + self.full_name + end + end + private def dependent_objects_map From 1b65e1950625febc970f0c2e46a3b8fd00d74424 Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Wed, 21 Jan 2015 09:29:29 +0000 Subject: [PATCH 09/65] added parent validations of name and status to taxon concept --- app/models/taxon_concept.rb | 22 ++++++++++ app/models/taxon_concept_observer.rb | 2 +- .../models/nomenclature_change/output_spec.rb | 2 +- spec/models/taxon_concept/validation_spec.rb | 41 ++++++++++++++++++- 4 files changed, 64 insertions(+), 3 deletions(-) diff --git a/app/models/taxon_concept.rb b/app/models/taxon_concept.rb index 7bbed616be..3d6796a58a 100644 --- a/app/models/taxon_concept.rb +++ b/app/models/taxon_concept.rb @@ -156,6 +156,12 @@ class TaxonConcept < ActiveRecord::Base validates :name_status, :presence => true validate :parent_in_same_taxonomy, :if => lambda { |tc| tc.parent } validate :parent_at_immediately_higher_rank, :if => lambda { |tc| tc.parent } + validate :parent_name_compatible, :if => lambda { |tc| + tc.parent && tc.rank && tc.full_name && ( + ['A', 'N'].include?(tc.name_status) || tc.name_status.blank? + ) + } + validate :parent_is_an_accepted_name, :if => lambda { |tc| tc.parent } validates :taxon_name_id, :presence => true, :unless => lambda { |tc| tc.taxon_name.try(:valid?) } validates :full_name, :uniqueness => { :scope => [:taxonomy_id, :author_year] } @@ -339,6 +345,22 @@ def taxonomy_can_be_changed end end + def parent_name_compatible + self.full_name = TaxonConcept.sanitize_full_name(full_name) + if Rank.in_range(Rank::VARIETY, Rank::SPECIES).include?(rank.name) && + full_name != expected_full_name(parent) + errors.add(:parent_id, "must have compatible name if rank is species, subspecies or variety") + return false + end + end + + def parent_is_an_accepted_name + unless ['A', 'N'].include?(parent.name_status) + errors.add(:parent_id, "must be an accepted name") + return false + end + end + def parent_in_same_taxonomy if taxonomy_id != parent.taxonomy_id errors.add(:parent_id, "must be in same taxonomy") diff --git a/app/models/taxon_concept_observer.rb b/app/models/taxon_concept_observer.rb index b590c4f4dd..b2e99b63a2 100644 --- a/app/models/taxon_concept_observer.rb +++ b/app/models/taxon_concept_observer.rb @@ -15,7 +15,7 @@ def before_validation(taxon_concept) taxon_concept.data = data return true unless taxon_concept.new_record? taxon_concept.full_name = if taxon_concept.rank && taxon_concept.parent && - taxon_concept.name_status == 'A' + ['A', 'N'].include?(taxon_concept.name_status) rank_name = taxon_concept.rank.name parent_full_name = taxon_concept.parent.full_name name = taxon_concept.taxon_name && taxon_concept.taxon_name.scientific_name diff --git a/spec/models/nomenclature_change/output_spec.rb b/spec/models/nomenclature_change/output_spec.rb index 3a092d415d..e83db62b9e 100644 --- a/spec/models/nomenclature_change/output_spec.rb +++ b/spec/models/nomenclature_change/output_spec.rb @@ -63,7 +63,7 @@ :new_name_status => nil ) } - specify { expect(output).to have(1).errors_on(:new_parent_id) } + specify { expect(output).to have(2).errors_on(:new_parent_id) } end context "when taxon concept specified" do let(:tc){ create_cites_eu_species } diff --git a/spec/models/taxon_concept/validation_spec.rb b/spec/models/taxon_concept/validation_spec.rb index 296a5f39a8..379fd44223 100644 --- a/spec/models/taxon_concept/validation_spec.rb +++ b/spec/models/taxon_concept/validation_spec.rb @@ -27,7 +27,46 @@ } specify { tc.should have(1).error_on(:parent_id) } end - + context "parent name is incompatible" do + let(:genus_tc){ + create_genus( + :taxonomy_id => cites_eu.id, + :taxon_name => build(:taxon_name, :scientific_name => 'Foobarus') + ) + } + let(:another_genus_tc){ + create_genus( + :taxonomy_id => cites_eu.id, + :taxon_name => build(:taxon_name, :scientific_name => 'Foobaria') + ) + } + let(:tc) { + create_species( + :taxonomy_id => cites_eu.id, + :parent_id => genus_tc.id + ) + } + let(:tc_with_incompatible_parent){ + tc.parent = another_genus_tc + tc + } + specify { tc_with_incompatible_parent.should have(1).error_on(:parent_id) } + end + context "parent is not an accepted name" do + let(:genus_tc){ + create_genus( + :taxonomy_id => cites_eu.id, + :name_status => 'S' + ) + } + let(:tc) { + build_species( + :taxonomy_id => cites_eu.id, + :parent_id => genus_tc.id + ) + } + specify { tc.should have(1).error_on(:parent_id) } + end context "parent rank is too high above child rank" do let(:tc) { build_class( From 7bc1364002687b498a194b18e04a4ce1a4b08171 Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Wed, 21 Jan 2015 09:31:36 +0000 Subject: [PATCH 10/65] removed parent validation from output --- app/models/nomenclature_change/output.rb | 29 +++++-------------- .../nomenclature_change/status_to_accepted.rb | 2 +- .../status_to_accepted/parent.html.erb | 7 ++--- 3 files changed, 12 insertions(+), 26 deletions(-) diff --git a/app/models/nomenclature_change/output.rb b/app/models/nomenclature_change/output.rb index 8e76414c94..ef06871efe 100644 --- a/app/models/nomenclature_change/output.rb +++ b/app/models/nomenclature_change/output.rb @@ -75,7 +75,6 @@ class NomenclatureChange::Output < ActiveRecord::Base :if => Proc.new { |c| c.taxon_concept_id.blank? } validate :validate_tmp_taxon_concept, :if => Proc.new { |c| c.will_create_taxon? || c.will_update_taxon? } - validate :compatible_parent?, if: Proc.new { |c| c.parent_status?} before_validation :populate_taxon_concept_fields, :if => Proc.new { |c| (c.new_record? || c.taxon_concept_id_changed?) && c.taxon_concept } @@ -173,29 +172,17 @@ def taxon_name_already_existing? return !TaxonConcept.where("lower(full_name) = ?", display_full_name.downcase).empty? end - def parent_status? - !nomenclature_change.nil? && nomenclature_change.status == "parent" - end - - def compatible_parent? - unless new_parent.rank.name == rank.parent_rank_name && - taxon_concept.full_name.include?(new_parent.full_name) && new_parent.name_status == 'A' && - taxonomy_id = Taxonomy.find_by_name(Taxonomy::CITES_EU).id - errors.add('', "must have a compatible parent") - return false - end - return true - end - def default_parent - name = taxon_concept.full_name if name_status == 'T' && Rank.in_range(Rank::VARIETY, Rank::SPECIES).include?(rank.name) - - taxonomy_id = Taxonomy.find_by_name(Taxonomy::CITES_EU).id - TaxonConcept.where("data->'rank_name' = ? AND UPPER(full_name) = UPPER(?) AND - taxonomy_id = ? AND name_status = 'A'", - rank.parent_rank_name, name.split.first, taxonomy_id).first + TaxonConcept.where( + taxonomy_id: Taxonomy.find_by_name(Taxonomy::CITES_EU).try(:id), + rank_id: Rank.find_by_name(rank.parent_rank_name).try(:id), + name_status: 'A' + ).where( + 'UPPER(SQUISH_NULL(full_name)) = UPPER(?)', + display_full_name.split.first + ).first else new_parent end diff --git a/app/models/nomenclature_change/status_to_accepted.rb b/app/models/nomenclature_change/status_to_accepted.rb index 33645ba93e..90818cd05e 100644 --- a/app/models/nomenclature_change/status_to_accepted.rb +++ b/app/models/nomenclature_change/status_to_accepted.rb @@ -38,7 +38,7 @@ def set_output_rank_id def set_output_parent_id return true unless needs_to_set_parent? && primary_output.new_parent_id.nil? primary_output && primary_output.taxon_concept && - primary_output.new_parent_id = primary_output.taxon_concept.parent_id + primary_output.new_parent_id = primary_output.default_parent.try(:id) end def needs_to_receive_associations? diff --git a/app/views/admin/nomenclature_changes/status_to_accepted/parent.html.erb b/app/views/admin/nomenclature_changes/status_to_accepted/parent.html.erb index f2fcb4b634..3fc4aaee13 100644 --- a/app/views/admin/nomenclature_changes/status_to_accepted/parent.html.erb +++ b/app/views/admin/nomenclature_changes/status_to_accepted/parent.html.erb @@ -8,11 +8,10 @@ <%= ff.text_field :new_parent_id, { :class => 'taxon-concept', - :'data-name' => ff.object.default_parent.try(:full_name), - :'data-name-status' => ff.object.default_parent.try(:name_status).to_s, + :'data-name' => ff.object.new_parent.try(:full_name), + :'data-name-status' => ff.object.new_parent.try(:name_status), :'data-name-status-filter' => ['A'].to_json, - :'data-taxonomy-id' => @taxonomy.id, - :'value' => ff.object.default_parent.try(:id) + :'data-taxonomy-id' => @taxonomy.id } %> From c74fa88bbd42034912fb657d6c75e62544184204 Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Wed, 21 Jan 2015 09:31:50 +0000 Subject: [PATCH 11/65] removed obsolete summary line --- app/models/nomenclature_change/output_taxon_concept_processor.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/models/nomenclature_change/output_taxon_concept_processor.rb b/app/models/nomenclature_change/output_taxon_concept_processor.rb index 011cae4149..8f3dc5c09a 100644 --- a/app/models/nomenclature_change/output_taxon_concept_processor.rb +++ b/app/models/nomenclature_change/output_taxon_concept_processor.rb @@ -53,7 +53,6 @@ def summary res << "#{@output.taxon_concept.full_name} author year changed from #{@output.taxon_concept.author_year} to #{@output.new_author_year}" end end - res << ["Will add nomenclature note for output #{full_name}"] res end From 3268f7dcae209e2c17a8e83b22336487b2fa8631 Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Wed, 21 Jan 2015 10:12:08 +0000 Subject: [PATCH 12/65] remmoved obsolete controller steps and views --- .../status_swap_controller.rb | 2 -- .../status_to_accepted_controller.rb | 9 +------- .../status_to_synonym_controller.rb | 2 -- .../nomenclature_change/status_to_accepted.rb | 2 +- .../status_swap/notes.html.erb | 19 --------------- .../status_to_accepted/notes.html.erb | 6 ----- .../status_to_accepted/receive.html.erb | 23 ------------------- .../status_to_synonym/notes.html.erb | 6 ----- 8 files changed, 2 insertions(+), 67 deletions(-) delete mode 100644 app/views/admin/nomenclature_changes/status_swap/notes.html.erb delete mode 100644 app/views/admin/nomenclature_changes/status_to_accepted/notes.html.erb delete mode 100644 app/views/admin/nomenclature_changes/status_to_accepted/receive.html.erb delete mode 100644 app/views/admin/nomenclature_changes/status_to_synonym/notes.html.erb diff --git a/app/controllers/admin/nomenclature_changes/status_swap_controller.rb b/app/controllers/admin/nomenclature_changes/status_swap_controller.rb index 9a6cf825f8..d2463e856c 100644 --- a/app/controllers/admin/nomenclature_changes/status_swap_controller.rb +++ b/app/controllers/admin/nomenclature_changes/status_swap_controller.rb @@ -12,8 +12,6 @@ def show when :swap set_taxonomy builder.build_secondary_output - when :notes - builder.build_output_notes when :legislation builder.build_legislation_reassignments skip_or_previous_step if @nomenclature_change.input.legislation_reassignments.empty? diff --git a/app/controllers/admin/nomenclature_changes/status_to_accepted_controller.rb b/app/controllers/admin/nomenclature_changes/status_to_accepted_controller.rb index f36424b442..fdc41ca275 100644 --- a/app/controllers/admin/nomenclature_changes/status_to_accepted_controller.rb +++ b/app/controllers/admin/nomenclature_changes/status_to_accepted_controller.rb @@ -12,13 +12,6 @@ def show when :parent skip_or_previous_step unless @nomenclature_change.needs_to_set_parent? set_taxonomy - when :receive - skip_or_previous_step unless @nomenclature_change.needs_to_receive_associations? - set_taxonomy - builder.build_secondary_output - builder.build_input - when :notes - builder.build_output_notes when :legislation builder.build_legislation_reassignments skip_or_previous_step if @nomenclature_change.input.nil? || @nomenclature_change.input.legislation_reassignments.empty? @@ -42,7 +35,7 @@ def update set_events set_taxonomy end - when :parent, :receive + when :parent set_taxonomy unless success end render_wizard @nomenclature_change diff --git a/app/controllers/admin/nomenclature_changes/status_to_synonym_controller.rb b/app/controllers/admin/nomenclature_changes/status_to_synonym_controller.rb index 8725a5d50d..6b7b457058 100644 --- a/app/controllers/admin/nomenclature_changes/status_to_synonym_controller.rb +++ b/app/controllers/admin/nomenclature_changes/status_to_synonym_controller.rb @@ -17,8 +17,6 @@ def show skip_or_previous_step unless @nomenclature_change.requires_accepted_name_assignment? set_taxonomy builder.build_secondary_output - when :notes - builder.build_output_notes when :legislation builder.build_legislation_reassignments skip_or_previous_step if @nomenclature_change.input.nil? || @nomenclature_change.input.legislation_reassignments.empty? diff --git a/app/models/nomenclature_change/status_to_accepted.rb b/app/models/nomenclature_change/status_to_accepted.rb index 90818cd05e..a93f53602b 100644 --- a/app/models/nomenclature_change/status_to_accepted.rb +++ b/app/models/nomenclature_change/status_to_accepted.rb @@ -42,7 +42,7 @@ def set_output_parent_id end def needs_to_receive_associations? - primary_output.try(:name_status) == 'S' + false end def needs_to_relay_associations? diff --git a/app/views/admin/nomenclature_changes/status_swap/notes.html.erb b/app/views/admin/nomenclature_changes/status_swap/notes.html.erb deleted file mode 100644 index 04e95d8669..0000000000 --- a/app/views/admin/nomenclature_changes/status_swap/notes.html.erb +++ /dev/null @@ -1,19 +0,0 @@ -

New status swap: nomenclature change notes

-<%= status_change_blurb %> -<%= nomenclature_change_form do |f| %> - <%= render partial: 'admin/nomenclature_changes/build/primary_output_notes', - locals: {f: f} %> - <%= f.fields_for :secondary_output do |ff| %> -
- -
- <%= render partial: 'admin/nomenclature_changes/build/nomenclature_notes', - locals: {ff: ff} - %> -
-
- <% end %> - -<% end %> diff --git a/app/views/admin/nomenclature_changes/status_to_accepted/notes.html.erb b/app/views/admin/nomenclature_changes/status_to_accepted/notes.html.erb deleted file mode 100644 index 8b520d4047..0000000000 --- a/app/views/admin/nomenclature_changes/status_to_accepted/notes.html.erb +++ /dev/null @@ -1,6 +0,0 @@ -

New status change to accepted name: nomenclature change notes

-<%= status_change_blurb %> -<%= nomenclature_change_form do |f| %> - <%= render partial: 'admin/nomenclature_changes/build/primary_output_notes', - locals: {f: f} %> -<% end %> diff --git a/app/views/admin/nomenclature_changes/status_to_accepted/receive.html.erb b/app/views/admin/nomenclature_changes/status_to_accepted/receive.html.erb deleted file mode 100644 index a645dd3523..0000000000 --- a/app/views/admin/nomenclature_changes/status_to_accepted/receive.html.erb +++ /dev/null @@ -1,23 +0,0 @@ -

New status change to accepted name

-<%= status_change_blurb %> -

- - This status change involves upgrading a synonym. It is possible to set the associations of the new name. -

-<%= nomenclature_change_form do |f| %> - <%= f.fields_for :input do |ff| %> -
- -
- <%= ff.text_field :taxon_concept_id, { - :class => 'taxon-concept clear-others', - :'data-name' => ff.object.taxon_concept.try(:full_name) || '', - :'data-name-status' => ff.object.taxon_concept.try(:name_status) || '', - :'data-name-status-filter' => ['A', 'N'].to_json, - :'data-taxonomy-id' => @taxonomy.id, - :value => ff.object.taxon_concept_id || '' - } %> -
-
- <% end %> -<% end %> diff --git a/app/views/admin/nomenclature_changes/status_to_synonym/notes.html.erb b/app/views/admin/nomenclature_changes/status_to_synonym/notes.html.erb deleted file mode 100644 index 9eb7ef9aed..0000000000 --- a/app/views/admin/nomenclature_changes/status_to_synonym/notes.html.erb +++ /dev/null @@ -1,6 +0,0 @@ -

New status change to synonym: nomenclature change notes

-<%= status_change_blurb %> -<%= nomenclature_change_form do |f| %> - <%= render partial: 'admin/nomenclature_changes/build/primary_output_notes', - locals: {f: f} %> -<% end %> From ce6688f53f914828e8eb260f0087ec79eefd5a35 Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Wed, 21 Jan 2015 11:10:33 +0000 Subject: [PATCH 13/65] update shipments to reflect change of accepted name in T -> S --- .../status_downgrade_processor.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/models/nomenclature_change/status_downgrade_processor.rb b/app/models/nomenclature_change/status_downgrade_processor.rb index 511beb4c9a..9abf7ebe40 100644 --- a/app/models/nomenclature_change/status_downgrade_processor.rb +++ b/app/models/nomenclature_change/status_downgrade_processor.rb @@ -45,6 +45,7 @@ def summary_line_long def run_t_to_s # if was a trade name and now is a synonym # remove has_trade_name associations + old_accepted_names = @input_or_output.taxon_concept.accepted_names_for_trade_name.all destroy_relationships( @input_or_output.taxon_concept.inverse_trade_name_relationships ) @@ -55,6 +56,9 @@ def run_t_to_s default_accepted_name = @linked_names.first if default_accepted_name update_shipments(@input_or_output.taxon_concept, default_accepted_name) + old_accepted_names.each do |old_accepted_name| + update_shipments_by_reported(@input_or_output.taxon_concept, old_accepted_name, default_accepted_name) + end end end @@ -86,4 +90,12 @@ def update_shipments(old_taxon_concept, new_taxon_concept) ) end + def update_shipments_by_reported(old_reported_taxon_concept, old_accepted_taxon_concept, new_taxon_concept) + Rails.logger.debug "Updating shipments where taxon concept = #{old_accepted_taxon_concept.full_name}, reported taxon concept = #{old_reported_taxon_concept.full_name}, to have taxon concept = #{new_taxon_concept.full_name}" + Trade::Shipment.update_all( + {taxon_concept_id: new_taxon_concept.id}, + {reported_taxon_concept_id: old_reported_taxon_concept.id, taxon_concept_id: old_accepted_taxon_concept.id } + ) + end + end From efdda4b6df975cc9e5c8ed000ffd95f8428a179f Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Wed, 21 Jan 2015 11:37:02 +0000 Subject: [PATCH 14/65] removed the obsolete legislation step & cleaned up the specs --- .../status_to_accepted_controller.rb | 3 - .../nomenclature_change/status_to_accepted.rb | 14 +--- .../status_to_accepted_controller_spec.rb | 21 ++---- .../shared/status_change_definitions.rb | 3 +- .../status_to_accepted/constructor_spec.rb | 71 ------------------- .../status_to_accepted/processor_spec.rb | 4 +- 6 files changed, 8 insertions(+), 108 deletions(-) delete mode 100644 spec/models/nomenclature_change/status_to_accepted/constructor_spec.rb diff --git a/app/controllers/admin/nomenclature_changes/status_to_accepted_controller.rb b/app/controllers/admin/nomenclature_changes/status_to_accepted_controller.rb index fdc41ca275..4612ba0505 100644 --- a/app/controllers/admin/nomenclature_changes/status_to_accepted_controller.rb +++ b/app/controllers/admin/nomenclature_changes/status_to_accepted_controller.rb @@ -12,9 +12,6 @@ def show when :parent skip_or_previous_step unless @nomenclature_change.needs_to_set_parent? set_taxonomy - when :legislation - builder.build_legislation_reassignments - skip_or_previous_step if @nomenclature_change.input.nil? || @nomenclature_change.input.legislation_reassignments.empty? when :summary processor = klass::Processor.new(@nomenclature_change) @summary = processor.summary diff --git a/app/models/nomenclature_change/status_to_accepted.rb b/app/models/nomenclature_change/status_to_accepted.rb index a93f53602b..3c3882d8a0 100644 --- a/app/models/nomenclature_change/status_to_accepted.rb +++ b/app/models/nomenclature_change/status_to_accepted.rb @@ -16,7 +16,7 @@ class NomenclatureChange::StatusToAccepted < NomenclatureChange include NomenclatureChange::StatusChangeHelpers build_steps( - :primary_output, :parent, :legislation, :summary + :primary_output, :parent, :summary ) validates :status, inclusion: { in: self.status_dict, @@ -54,18 +54,6 @@ def needs_to_set_parent? end def build_auto_reassignments - # Reassignments will only be required when there is an input - # from which to reassign - if input - builder = NomenclatureChange::StatusToAccepted::Constructor.new(self) - builder.build_parent_reassignments - builder.build_name_reassignments - builder.build_distribution_reassignments - builder.build_legislation_reassignments - builder.build_common_names_reassignments - builder.build_references_reassignments - # no trade reassignments - end true end diff --git a/spec/controllers/admin/nomenclature_changes/status_to_accepted_controller_spec.rb b/spec/controllers/admin/nomenclature_changes/status_to_accepted_controller_spec.rb index 866ebb9511..06c7148870 100644 --- a/spec/controllers/admin/nomenclature_changes/status_to_accepted_controller_spec.rb +++ b/spec/controllers/admin/nomenclature_changes/status_to_accepted_controller_spec.rb @@ -14,26 +14,13 @@ response.should render_template('primary_output') end end - context :reassignments do + context :parent do before(:each) do @status_change = s_to_a_with_input end - context "when legislation present" do - before(:each) do - create_cites_I_addition(taxon_concept: input_species) - end - it 'renders the legislation template' do - get :show, id: :legislation, nomenclature_change_id: @status_change.id - response.should render_template('legislation') - end - end - context "when no legislation" do - it 'redirects to next step' do - get :show, id: :legislation, nomenclature_change_id: @status_change.id - response.should redirect_to(admin_nomenclature_change_status_to_accepted_url( - nomenclature_change_id: assigns(:nomenclature_change).id, :id => 'summary' - )) - end + it 'renders the parent template' do + get :show, id: :parent, nomenclature_change_id: @status_change.id + response.should render_template('parent') end end context :summary do diff --git a/spec/models/nomenclature_change/shared/status_change_definitions.rb b/spec/models/nomenclature_change/shared/status_change_definitions.rb index f7ba0e9d08..e5449f53ac 100644 --- a/spec/models/nomenclature_change/shared/status_change_definitions.rb +++ b/spec/models/nomenclature_change/shared/status_change_definitions.rb @@ -91,8 +91,7 @@ taxon_concept_id: input_synonym.id, new_name_status: 'A' }, - input_attributes: { taxon_concept_id: input_species.id }, - status: NomenclatureChange::StatusToAccepted::LEGISLATION + status: NomenclatureChange::StatusToAccepted::PRIMARY_OUTPUT ).reload } let(:s_to_a_with_swap){ diff --git a/spec/models/nomenclature_change/status_to_accepted/constructor_spec.rb b/spec/models/nomenclature_change/status_to_accepted/constructor_spec.rb deleted file mode 100644 index dc1519454a..0000000000 --- a/spec/models/nomenclature_change/status_to_accepted/constructor_spec.rb +++ /dev/null @@ -1,71 +0,0 @@ -require 'spec_helper' - -describe NomenclatureChange::StatusToAccepted::Constructor do - include_context 'status_change_definitions' - - let(:constructor){ NomenclatureChange::StatusToAccepted::Constructor.new(status_change) } - - describe :build_input do - let(:status_change){ s_to_a_with_primary_output } - before(:each) do - @old_input = status_change.input - constructor.build_input - end - context "when previously no input in place" do - specify{ expect(status_change.input).not_to be_nil } - end - context "when previously input in place" do - let(:status_change){ s_to_a_with_input } - specify{ expect(status_change.input).to eq(@old_input) } - end - end - - context "reassignments" do - let(:nc){ s_to_a_with_input } - let(:status_change){ nc } - let(:input){ nc.input } - describe :build_parent_reassignments do - before(:each) do - @old_reassignments = input.parent_reassignments - constructor.build_parent_reassignments - end - include_context 'parent_reassignments_constructor_examples' - end - describe :build_name_reassignments do - before(:each) do - @old_reassignments = input.name_reassignments - constructor.build_name_reassignments - end - include_context 'name_reassignments_constructor_examples' - end - describe :build_distribution_reassignments do - before(:each) do - @old_reassignments = input.distribution_reassignments - constructor.build_distribution_reassignments - end - include_context 'distribution_reassignments_constructor_examples' - end - describe :build_legislation_reassignments do - before(:each) do - @old_reassignments = input.legislation_reassignments - constructor.build_legislation_reassignments - end - include_context 'legislation_reassignments_constructor_examples' - end - describe :build_common_names_reassignments do - before(:each) do - @old_reassignments = input.reassignments - constructor.build_common_names_reassignments - end - include_context 'common_name_reassignments_constructor_examples' - end - describe :build_references_reassignments do - before(:each) do - @old_reassignments = input.reassignments - constructor.build_references_reassignments - end - include_context 'reference_reassignments_constructor_examples' - end - end - -end diff --git a/spec/models/nomenclature_change/status_to_accepted/processor_spec.rb b/spec/models/nomenclature_change/status_to_accepted/processor_spec.rb index 1d6f5bfb59..0cdbf52d2e 100644 --- a/spec/models/nomenclature_change/status_to_accepted/processor_spec.rb +++ b/spec/models/nomenclature_change/status_to_accepted/processor_spec.rb @@ -41,7 +41,7 @@ new_name_status: 'A' }, input_attributes: { taxon_concept_id: input_species.id }, - status: NomenclatureChange::StatusToAccepted::LEGISLATION + status: NomenclatureChange::StatusToAccepted::PRIMARY_OUTPUT ).reload } let(:status_change){ s_to_a_with_input } @@ -68,7 +68,7 @@ new_name_status: 'A' }, input_attributes: { taxon_concept_id: input_species.id }, - status: NomenclatureChange::StatusToAccepted::LEGISLATION + status: NomenclatureChange::StatusToAccepted::PRIMARY_OUTPUT ).reload } let(:status_change){ s_to_a_with_input } From 4b41c341e5233a8a8a23f0b2776721e2306d467e Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Wed, 21 Jan 2015 13:34:22 +0000 Subject: [PATCH 15/65] Ancestors added to raw and comptab shipments downloads --- app/models/trade/shipment_report_queries.rb | 13 ++++++++++++- app/models/trade/shipments_comptab_export.rb | 5 ++++- app/models/trade/shipments_export.rb | 4 ++++ config/locales/trade_reports.yml | 12 ++++++++++++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/app/models/trade/shipment_report_queries.rb b/app/models/trade/shipment_report_queries.rb index eff27735c2..765b7cbec0 100644 --- a/app/models/trade/shipment_report_queries.rb +++ b/app/models/trade/shipment_report_queries.rb @@ -9,6 +9,10 @@ def raw_query(options) full_name_with_spp(ranks.name, taxon_concept_full_name) AS taxon, reported_taxon_concept_id, full_name_with_spp(reported_taxon_ranks.name, reported_taxon_concept_full_name) AS reported_taxon, + taxon_concept_class_name AS class_name, + taxon_concept_order_name AS order_name, + taxon_concept_family_name AS family_name, + taxon_concept_genus_name AS genus_name, importer_id, importers.iso_code2 AS importer, exporter_id, @@ -73,9 +77,12 @@ def comptab_query(options) "SELECT year, appendix, - taxon_concept_family_name AS family, taxon_concept_id, full_name_with_spp(ranks.name, taxon_concept_full_name) AS taxon, + taxon_concept_class_name AS class_name, + taxon_concept_order_name AS order_name, + taxon_concept_family_name AS family_name, + taxon_concept_genus_name AS genus_name, importer_id, importers.iso_code2 AS importer, exporter_id, @@ -121,6 +128,10 @@ def comptab_query(options) taxon_concept_family_name, taxon_concept_id, taxon_concept_full_name, + class_name, + order_name, + family_name, + genus_name, ranks.name, importer_id, importers.iso_code2, diff --git a/app/models/trade/shipments_comptab_export.rb b/app/models/trade/shipments_comptab_export.rb index ced08d1f8d..f0cf4ae1af 100644 --- a/app/models/trade/shipments_comptab_export.rb +++ b/app/models/trade/shipments_comptab_export.rb @@ -31,9 +31,12 @@ def available_columns { :year => {}, :appendix => {}, - :family => {}, :taxon => {}, :taxon_concept_id => {:internal => true}, + :class_name => {}, + :order_name => {}, + :family_name => {}, + :genus_name => {}, :importer => {}, :exporter => {}, :country_of_origin => {}, diff --git a/app/models/trade/shipments_export.rb b/app/models/trade/shipments_export.rb index c02a583c5a..5327294513 100644 --- a/app/models/trade/shipments_export.rb +++ b/app/models/trade/shipments_export.rb @@ -99,6 +99,10 @@ def available_columns :appendix => {}, :taxon => {}, :taxon_concept_id => {:internal => true}, + :class_name => {:internal => true}, + :order_name => {:internal => true}, + :family_name => {:internal => true}, + :genus_name => {:internal => true}, :reported_taxon => {:internal => true}, :reported_taxon_concept_id => {:internal => true}, :term => {:en => :term_name_en, :es => :term_name_es, :fr => :term_name_fr}, diff --git a/config/locales/trade_reports.yml b/config/locales/trade_reports.yml index 8aef6e5b9d..8da1b4a8fe 100644 --- a/config/locales/trade_reports.yml +++ b/config/locales/trade_reports.yml @@ -4,6 +4,10 @@ en: year: 'Year' appendix: 'App.' family: 'Family' + class_name: 'Class' + order_name: 'Order' + family_name: 'Family' + genus_name: 'Genus' taxon: 'Taxon' taxon_concept_id: 'Taxon ID' reported_taxon: 'Reported Taxon' @@ -33,6 +37,10 @@ es: year: 'Año' appendix: 'Apéndice' family: 'Familia' + class_name: 'Clase' + order_name: 'Orden' + family_name: 'Familia' + genus_name: 'Género' taxon: 'Taxón' taxon_concept_id: 'Taxón ID' reported_taxon: 'Taxón Reportado' @@ -62,6 +70,10 @@ fr: year: 'Année' appendix: 'Annexe' family: 'Famille' + class_name: 'Classe' + order_name: 'Ordre' + family_name: 'Famille' + genus_name: 'Genre' taxon: 'Taxon' taxon_concept_id: 'Taxon ID' # reported_taxon: 'Reported Taxon' From 51ac269cb657e34388de536dec836656c3cab176 Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Wed, 21 Jan 2015 13:37:35 +0000 Subject: [PATCH 16/65] Migration and sql view added --- ..._ancestors_name_to_trade_shipments_view.rb | 11 ++++++ .../20150121111134.sql | 35 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 db/migrate/20150121111134_add_ancestors_name_to_trade_shipments_view.rb create mode 100644 db/views/trade_shipments_with_taxa_view/20150121111134.sql diff --git a/db/migrate/20150121111134_add_ancestors_name_to_trade_shipments_view.rb b/db/migrate/20150121111134_add_ancestors_name_to_trade_shipments_view.rb new file mode 100644 index 0000000000..5a650c01d0 --- /dev/null +++ b/db/migrate/20150121111134_add_ancestors_name_to_trade_shipments_view.rb @@ -0,0 +1,11 @@ +class AddAncestorsNameToTradeShipmentsView < ActiveRecord::Migration + def up + execute "DROP VIEW IF EXISTS trade_shipments_with_taxa_view" + execute "CREATE VIEW trade_shipments_with_taxa_view AS #{view_sql('20150121111134', 'trade_shipments_with_taxa_view')}" + end + + def down + execute "DROP VIEW IF EXISTS trade_shipments_with_taxa_view" + execute "CREATE VIEW trade_shipments_with_taxa_view AS #{view_sql('20141223141125', 'trade_shipments_with_taxa_view')}" + end +end diff --git a/db/views/trade_shipments_with_taxa_view/20150121111134.sql b/db/views/trade_shipments_with_taxa_view/20150121111134.sql new file mode 100644 index 0000000000..4e5bc81e8f --- /dev/null +++ b/db/views/trade_shipments_with_taxa_view/20150121111134.sql @@ -0,0 +1,35 @@ +SELECT + shipments.*, + taxon_concepts.full_name AS taxon_concept_full_name, + taxon_concepts.author_year AS taxon_concept_author_year, + taxon_concepts.name_status AS taxon_concept_name_status, + taxon_concepts.rank_id AS taxon_concept_rank_id, + (taxon_concepts.data->'kingdom_id')::INT AS taxon_concept_kingdom_id, + (taxon_concepts.data->'phylum_id')::INT AS taxon_concept_phylum_id, + (taxon_concepts.data->'class_id')::INT AS taxon_concept_class_id, + (taxon_concepts.data->'order_id')::INT AS taxon_concept_order_id, + (taxon_concepts.data->'family_id')::INT AS taxon_concept_family_id, + (taxon_concepts.data->'subfamily_id')::INT AS taxon_concept_subfamily_id, + (taxon_concepts.data->'genus_id')::INT AS taxon_concept_genus_id, + (taxon_concepts.data->'species_id')::INT AS taxon_concept_species_id, + (taxon_concepts.data->'class_name') AS taxon_concept_class_name, + (taxon_concepts.data->'order_name') AS taxon_concept_order_name, + (taxon_concepts.data->'family_name') AS taxon_concept_family_name, + (taxon_concepts.data->'genus_name') AS taxon_concept_genus_name, + reported_taxon_concepts.full_name AS reported_taxon_concept_full_name, + reported_taxon_concepts.author_year AS reported_taxon_concept_author_year, + reported_taxon_concepts.name_status AS reported_taxon_concept_name_status, + reported_taxon_concepts.rank_id AS reported_taxon_concept_rank_id, + (reported_taxon_concepts.data->'kingdom_id')::INT AS reported_taxon_concept_kingdom_id, + (reported_taxon_concepts.data->'phylum_id')::INT AS reported_taxon_concept_phylum_id, + (reported_taxon_concepts.data->'class_id')::INT AS reported_taxon_concept_class_id, + (reported_taxon_concepts.data->'order_id')::INT AS reported_taxon_concept_order_id, + (reported_taxon_concepts.data->'family_id')::INT AS reported_taxon_concept_family_id, + (reported_taxon_concepts.data->'subfamily_id')::INT AS reported_taxon_concept_subfamily_id, + (reported_taxon_concepts.data->'genus_id')::INT AS reported_taxon_concept_genus_id, + (reported_taxon_concepts.data->'species_id')::INT AS reported_taxon_concept_species_id +FROM trade_shipments shipments +JOIN taxon_concepts + ON taxon_concept_id = taxon_concepts.id +LEFT JOIN taxon_concepts reported_taxon_concepts + ON reported_taxon_concept_id = reported_taxon_concepts.id; From 2ffa0f6305cdb0b254588fc352de12548391b297 Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Wed, 21 Jan 2015 14:23:35 +0000 Subject: [PATCH 17/65] Amended geo entity autocomplete by starting letter --- .../downloads_for_cites_listings_controller.js.coffee | 4 ++-- .../downloads_for_cites_restrictions_controller.js.coffee | 4 ++-- .../downloads_for_cms_listings_controller.js.coffee | 4 ++-- .../downloads_for_eu_decisions_controller.js.coffee | 4 ++-- .../downloads_for_eu_listings_controller.js.coffee | 4 ++-- .../species/controllers/search_controller.js.coffee | 2 +- .../javascripts/trade/controllers/search_controller.js.coffee | 4 +++- 7 files changed, 14 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/species/controllers/downloads_for_cites_listings_controller.js.coffee b/app/assets/javascripts/species/controllers/downloads_for_cites_listings_controller.js.coffee index cac49b3f04..2040212f38 100644 --- a/app/assets/javascripts/species/controllers/downloads_for_cites_listings_controller.js.coffee +++ b/app/assets/javascripts/species/controllers/downloads_for_cites_listings_controller.js.coffee @@ -32,7 +32,7 @@ Species.DownloadsForCitesListingsController = Ember.Controller.extend autoCompleteRegions: ( -> if @get('geoEntityQuery') && @get('geoEntityQuery').length > 0 - re = new RegExp("^"+@get('geoEntityQuery'),"i") + re = new RegExp(@get('geoEntityQuery'),"i") @get('controllers.geoEntities.regions') .filter (item, index, enumerable) => re.test item.get('name') @@ -42,7 +42,7 @@ Species.DownloadsForCitesListingsController = Ember.Controller.extend autoCompleteCountries: ( -> if @get('geoEntityQuery') && @get('geoEntityQuery').length > 0 - re = new RegExp("^"+@get('geoEntityQuery'),"i") + re = new RegExp(@get('geoEntityQuery'),"i") @get('controllers.geoEntities.countries') .filter (item, index, enumerable) => re.test item.get('name') diff --git a/app/assets/javascripts/species/controllers/downloads_for_cites_restrictions_controller.js.coffee b/app/assets/javascripts/species/controllers/downloads_for_cites_restrictions_controller.js.coffee index 9f73a759d6..4ab7e77a5b 100644 --- a/app/assets/javascripts/species/controllers/downloads_for_cites_restrictions_controller.js.coffee +++ b/app/assets/javascripts/species/controllers/downloads_for_cites_restrictions_controller.js.coffee @@ -42,7 +42,7 @@ Species.DownloadsForCitesRestrictionsController = Ember.Controller.extend autoCompleteRegions: ( -> if @get('geoEntityQuery') && @get('geoEntityQuery').length > 0 - re = new RegExp("^"+@get('geoEntityQuery'),"i") + re = new RegExp(@get('geoEntityQuery'),"i") @get('controllers.geoEntities.regions') .filter (item, index, enumerable) => re.test item.get('name') @@ -52,7 +52,7 @@ Species.DownloadsForCitesRestrictionsController = Ember.Controller.extend autoCompleteCountries: ( -> if @get('geoEntityQuery') && @get('geoEntityQuery').length > 0 - re = new RegExp("^"+@get('geoEntityQuery'),"i") + re = new RegExp(@get('geoEntityQuery'),"i") @get('controllers.geoEntities.countries') .filter (item, index, enumerable) => re.test item.get('name') diff --git a/app/assets/javascripts/species/controllers/downloads_for_cms_listings_controller.js.coffee b/app/assets/javascripts/species/controllers/downloads_for_cms_listings_controller.js.coffee index 35f19a6290..57a04da0c9 100644 --- a/app/assets/javascripts/species/controllers/downloads_for_cms_listings_controller.js.coffee +++ b/app/assets/javascripts/species/controllers/downloads_for_cms_listings_controller.js.coffee @@ -32,7 +32,7 @@ Species.DownloadsForCmsListingsController = Ember.Controller.extend autoCompleteRegions: ( -> if @get('geoEntityQuery') && @get('geoEntityQuery').length > 0 - re = new RegExp("^"+@get('geoEntityQuery'),"i") + re = new RegExp(@get('geoEntityQuery'),"i") @get('controllers.geoEntities.regions') .filter (item, index, enumerable) => re.test item.get('name') @@ -42,7 +42,7 @@ Species.DownloadsForCmsListingsController = Ember.Controller.extend autoCompleteCountries: ( -> if @get('geoEntityQuery') && @get('geoEntityQuery').length > 0 - re = new RegExp("^"+@get('geoEntityQuery'),"i") + re = new RegExp(@get('geoEntityQuery'),"i") @get('controllers.geoEntities.countries') .filter (item, index, enumerable) => re.test item.get('name') diff --git a/app/assets/javascripts/species/controllers/downloads_for_eu_decisions_controller.js.coffee b/app/assets/javascripts/species/controllers/downloads_for_eu_decisions_controller.js.coffee index 8122b4e1cf..5e24a4ff39 100644 --- a/app/assets/javascripts/species/controllers/downloads_for_eu_decisions_controller.js.coffee +++ b/app/assets/javascripts/species/controllers/downloads_for_eu_decisions_controller.js.coffee @@ -44,7 +44,7 @@ Species.DownloadsForEuDecisionsController = Ember.Controller.extend autoCompleteRegions: ( -> if @get('geoEntityQuery') && @get('geoEntityQuery').length > 0 - re = new RegExp("^"+@get('geoEntityQuery'),"i") + re = new RegExp(@get('geoEntityQuery'),"i") @get('controllers.geoEntities.regions') .filter (item, index, enumerable) => re.test item.get('name') @@ -54,7 +54,7 @@ Species.DownloadsForEuDecisionsController = Ember.Controller.extend autoCompleteCountries: ( -> if @get('geoEntityQuery') && @get('geoEntityQuery').length > 0 - re = new RegExp("^"+@get('geoEntityQuery'),"i") + re = new RegExp(@get('geoEntityQuery'),"i") @get('controllers.geoEntities.countries') .filter (item, index, enumerable) => re.test item.get('name') diff --git a/app/assets/javascripts/species/controllers/downloads_for_eu_listings_controller.js.coffee b/app/assets/javascripts/species/controllers/downloads_for_eu_listings_controller.js.coffee index 83e7c9f837..e3e3483b14 100644 --- a/app/assets/javascripts/species/controllers/downloads_for_eu_listings_controller.js.coffee +++ b/app/assets/javascripts/species/controllers/downloads_for_eu_listings_controller.js.coffee @@ -33,7 +33,7 @@ Species.DownloadsForEuListingsController = Ember.Controller.extend autoCompleteRegions: ( -> if @get('geoEntityQuery') && @get('geoEntityQuery').length > 0 - re = new RegExp("^"+@get('geoEntityQuery'),"i") + re = new RegExp(@get('geoEntityQuery'),"i") @get('controllers.geoEntities.regions') .filter (item, index, enumerable) => re.test item.get('name') @@ -43,7 +43,7 @@ Species.DownloadsForEuListingsController = Ember.Controller.extend autoCompleteCountries: ( -> if @get('geoEntityQuery') && @get('geoEntityQuery').length > 0 - re = new RegExp("^"+@get('geoEntityQuery'),"i") + re = new RegExp(@get('geoEntityQuery'),"i") @get('controllers.geoEntities.countries') .filter (item, index, enumerable) => re.test item.get('name') diff --git a/app/assets/javascripts/species/controllers/search_controller.js.coffee b/app/assets/javascripts/species/controllers/search_controller.js.coffee index 02b90ecf01..b3efb98508 100644 --- a/app/assets/javascripts/species/controllers/search_controller.js.coffee +++ b/app/assets/javascripts/species/controllers/search_controller.js.coffee @@ -32,7 +32,7 @@ Species.SearchController = Ember.Controller.extend Species.Spinner, ).property('taxonConceptQuery') geoEntityQueryObserver: ( -> - re = new RegExp("^"+@get('geoEntityQuery'),"i") + re = new RegExp(@get('geoEntityQuery'),"i") @set 'autoCompleteCountries', @get('controllers.geoEntities.countries') .filter (item, index, enumerable) => diff --git a/app/assets/javascripts/trade/controllers/search_controller.js.coffee b/app/assets/javascripts/trade/controllers/search_controller.js.coffee index 9918d27b44..5bb0f2a13b 100644 --- a/app/assets/javascripts/trade/controllers/search_controller.js.coffee +++ b/app/assets/javascripts/trade/controllers/search_controller.js.coffee @@ -114,7 +114,9 @@ Trade.SearchController = Ember.Controller.extend Trade.QueryParams, Trade.Flash, autoCompleteObjects: (collectionName, columnName, query) -> return @get(collectionName) unless query - re = new RegExp("^" + query, "i") + if collectionName != 'controllers.geoEntities' + query = "^" + query + re = new RegExp(query, "i") @get(collectionName).filter (element) -> re.test(element.get(columnName)) From 814083f0756396e6d80384db86d51bc7a344997b Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Wed, 21 Jan 2015 15:34:37 +0000 Subject: [PATCH 18/65] RegExp fixed --- .../downloads_for_cites_listings_controller.js.coffee | 4 ++-- .../downloads_for_cites_restrictions_controller.js.coffee | 4 ++-- .../downloads_for_cms_listings_controller.js.coffee | 4 ++-- .../downloads_for_eu_decisions_controller.js.coffee | 4 ++-- .../downloads_for_eu_listings_controller.js.coffee | 4 ++-- .../species/controllers/search_controller.js.coffee | 2 +- .../javascripts/trade/controllers/search_controller.js.coffee | 2 ++ 7 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/species/controllers/downloads_for_cites_listings_controller.js.coffee b/app/assets/javascripts/species/controllers/downloads_for_cites_listings_controller.js.coffee index 2040212f38..57906bc863 100644 --- a/app/assets/javascripts/species/controllers/downloads_for_cites_listings_controller.js.coffee +++ b/app/assets/javascripts/species/controllers/downloads_for_cites_listings_controller.js.coffee @@ -32,7 +32,7 @@ Species.DownloadsForCitesListingsController = Ember.Controller.extend autoCompleteRegions: ( -> if @get('geoEntityQuery') && @get('geoEntityQuery').length > 0 - re = new RegExp(@get('geoEntityQuery'),"i") + re = new RegExp("(^| )"+@get('geoEntityQuery'),"i") @get('controllers.geoEntities.regions') .filter (item, index, enumerable) => re.test item.get('name') @@ -42,7 +42,7 @@ Species.DownloadsForCitesListingsController = Ember.Controller.extend autoCompleteCountries: ( -> if @get('geoEntityQuery') && @get('geoEntityQuery').length > 0 - re = new RegExp(@get('geoEntityQuery'),"i") + re = new RegExp("(^| )"+@get('geoEntityQuery'),"i") @get('controllers.geoEntities.countries') .filter (item, index, enumerable) => re.test item.get('name') diff --git a/app/assets/javascripts/species/controllers/downloads_for_cites_restrictions_controller.js.coffee b/app/assets/javascripts/species/controllers/downloads_for_cites_restrictions_controller.js.coffee index 4ab7e77a5b..e9d06277bb 100644 --- a/app/assets/javascripts/species/controllers/downloads_for_cites_restrictions_controller.js.coffee +++ b/app/assets/javascripts/species/controllers/downloads_for_cites_restrictions_controller.js.coffee @@ -42,7 +42,7 @@ Species.DownloadsForCitesRestrictionsController = Ember.Controller.extend autoCompleteRegions: ( -> if @get('geoEntityQuery') && @get('geoEntityQuery').length > 0 - re = new RegExp(@get('geoEntityQuery'),"i") + re = new RegExp("(^| )"+@get('geoEntityQuery'),"i") @get('controllers.geoEntities.regions') .filter (item, index, enumerable) => re.test item.get('name') @@ -52,7 +52,7 @@ Species.DownloadsForCitesRestrictionsController = Ember.Controller.extend autoCompleteCountries: ( -> if @get('geoEntityQuery') && @get('geoEntityQuery').length > 0 - re = new RegExp(@get('geoEntityQuery'),"i") + re = new RegExp("(^| )"+@get('geoEntityQuery'),"i") @get('controllers.geoEntities.countries') .filter (item, index, enumerable) => re.test item.get('name') diff --git a/app/assets/javascripts/species/controllers/downloads_for_cms_listings_controller.js.coffee b/app/assets/javascripts/species/controllers/downloads_for_cms_listings_controller.js.coffee index 57a04da0c9..c947a9f4a5 100644 --- a/app/assets/javascripts/species/controllers/downloads_for_cms_listings_controller.js.coffee +++ b/app/assets/javascripts/species/controllers/downloads_for_cms_listings_controller.js.coffee @@ -32,7 +32,7 @@ Species.DownloadsForCmsListingsController = Ember.Controller.extend autoCompleteRegions: ( -> if @get('geoEntityQuery') && @get('geoEntityQuery').length > 0 - re = new RegExp(@get('geoEntityQuery'),"i") + re = new RegExp("(^| )"+@get('geoEntityQuery'),"i") @get('controllers.geoEntities.regions') .filter (item, index, enumerable) => re.test item.get('name') @@ -42,7 +42,7 @@ Species.DownloadsForCmsListingsController = Ember.Controller.extend autoCompleteCountries: ( -> if @get('geoEntityQuery') && @get('geoEntityQuery').length > 0 - re = new RegExp(@get('geoEntityQuery'),"i") + re = new RegExp("(^| )"+@get('geoEntityQuery'),"i") @get('controllers.geoEntities.countries') .filter (item, index, enumerable) => re.test item.get('name') diff --git a/app/assets/javascripts/species/controllers/downloads_for_eu_decisions_controller.js.coffee b/app/assets/javascripts/species/controllers/downloads_for_eu_decisions_controller.js.coffee index 5e24a4ff39..37a31ddcdb 100644 --- a/app/assets/javascripts/species/controllers/downloads_for_eu_decisions_controller.js.coffee +++ b/app/assets/javascripts/species/controllers/downloads_for_eu_decisions_controller.js.coffee @@ -44,7 +44,7 @@ Species.DownloadsForEuDecisionsController = Ember.Controller.extend autoCompleteRegions: ( -> if @get('geoEntityQuery') && @get('geoEntityQuery').length > 0 - re = new RegExp(@get('geoEntityQuery'),"i") + re = new RegExp("(^| )"+@get('geoEntityQuery'),"i") @get('controllers.geoEntities.regions') .filter (item, index, enumerable) => re.test item.get('name') @@ -54,7 +54,7 @@ Species.DownloadsForEuDecisionsController = Ember.Controller.extend autoCompleteCountries: ( -> if @get('geoEntityQuery') && @get('geoEntityQuery').length > 0 - re = new RegExp(@get('geoEntityQuery'),"i") + re = new RegExp("(^| )"+@get('geoEntityQuery'),"i") @get('controllers.geoEntities.countries') .filter (item, index, enumerable) => re.test item.get('name') diff --git a/app/assets/javascripts/species/controllers/downloads_for_eu_listings_controller.js.coffee b/app/assets/javascripts/species/controllers/downloads_for_eu_listings_controller.js.coffee index e3e3483b14..ab5882d3d7 100644 --- a/app/assets/javascripts/species/controllers/downloads_for_eu_listings_controller.js.coffee +++ b/app/assets/javascripts/species/controllers/downloads_for_eu_listings_controller.js.coffee @@ -33,7 +33,7 @@ Species.DownloadsForEuListingsController = Ember.Controller.extend autoCompleteRegions: ( -> if @get('geoEntityQuery') && @get('geoEntityQuery').length > 0 - re = new RegExp(@get('geoEntityQuery'),"i") + re = new RegExp("(^| )"+@get('geoEntityQuery'),"i") @get('controllers.geoEntities.regions') .filter (item, index, enumerable) => re.test item.get('name') @@ -43,7 +43,7 @@ Species.DownloadsForEuListingsController = Ember.Controller.extend autoCompleteCountries: ( -> if @get('geoEntityQuery') && @get('geoEntityQuery').length > 0 - re = new RegExp(@get('geoEntityQuery'),"i") + re = new RegExp("(^| )"+@get('geoEntityQuery'),"i") @get('controllers.geoEntities.countries') .filter (item, index, enumerable) => re.test item.get('name') diff --git a/app/assets/javascripts/species/controllers/search_controller.js.coffee b/app/assets/javascripts/species/controllers/search_controller.js.coffee index b3efb98508..71399a4622 100644 --- a/app/assets/javascripts/species/controllers/search_controller.js.coffee +++ b/app/assets/javascripts/species/controllers/search_controller.js.coffee @@ -32,7 +32,7 @@ Species.SearchController = Ember.Controller.extend Species.Spinner, ).property('taxonConceptQuery') geoEntityQueryObserver: ( -> - re = new RegExp(@get('geoEntityQuery'),"i") + re = new RegExp("(^| )"+@get('geoEntityQuery'),"i") @set 'autoCompleteCountries', @get('controllers.geoEntities.countries') .filter (item, index, enumerable) => diff --git a/app/assets/javascripts/trade/controllers/search_controller.js.coffee b/app/assets/javascripts/trade/controllers/search_controller.js.coffee index 5bb0f2a13b..a2c11be64a 100644 --- a/app/assets/javascripts/trade/controllers/search_controller.js.coffee +++ b/app/assets/javascripts/trade/controllers/search_controller.js.coffee @@ -116,6 +116,8 @@ Trade.SearchController = Ember.Controller.extend Trade.QueryParams, Trade.Flash, return @get(collectionName) unless query if collectionName != 'controllers.geoEntities' query = "^" + query + else + query = "(^| )" + query re = new RegExp(query, "i") @get(collectionName).filter (element) -> re.test(element.get(columnName)) From 8a4076825a2576439bba43aa61282e9bbba7a240 Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Wed, 21 Jan 2015 17:11:22 +0000 Subject: [PATCH 19/65] Validation errors alphabetically sorted --- app/serializers/trade/show_annual_report_upload_serializer.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/serializers/trade/show_annual_report_upload_serializer.rb b/app/serializers/trade/show_annual_report_upload_serializer.rb index d6f3395877..2c1c2824ee 100644 --- a/app/serializers/trade/show_annual_report_upload_serializer.rb +++ b/app/serializers/trade/show_annual_report_upload_serializer.rb @@ -4,6 +4,10 @@ class Trade::ShowAnnualReportUploadSerializer < ActiveModel::Serializer :file_name, :is_done, :has_primary_errors, :created_at, :updated_at, :created_by, :updated_by has_many :validation_errors + + def validation_errors + object.validation_errors.sort_by(&:error_message) + end def file_name object.csv_source_file.try(:path) && File.basename(object.csv_source_file.path) end From 4b94511a59a5e84bb586ecb170399413dc19f7e4 Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Thu, 22 Jan 2015 09:46:23 +0000 Subject: [PATCH 20/65] Removed set blank option from Year --- .../annual_report_upload/_batch_operations.handlebars | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/assets/javascripts/trade/templates/annual_report_upload/_batch_operations.handlebars b/app/assets/javascripts/trade/templates/annual_report_upload/_batch_operations.handlebars index 95fcecfa51..d26ca8bf27 100644 --- a/app/assets/javascripts/trade/templates/annual_report_upload/_batch_operations.handlebars +++ b/app/assets/javascripts/trade/templates/annual_report_upload/_batch_operations.handlebars @@ -118,9 +118,6 @@ -
- Trade Codes + Trade Codes And Quantity

Term Code

Current value: {{currentShipment.termCode}}

{{view Trade.Select2 - prompt="Please select term code value" + prompt="Select" contentBinding="controllers.terms" optionValuePath="content.code" optionLabelPath="content.code" @@ -61,7 +61,7 @@

Unit Code

Current value: {{currentShipment.unitCode}}

{{view Trade.Select2 - prompt="Please select unit code value" + prompt="Select" contentBinding="controllers.units" optionValuePath="content.code" optionLabelPath="content.code" @@ -72,7 +72,7 @@

Purpose Code

Current value: {{currentShipment.purposeCode}}

{{view Trade.Select2 - prompt="Please select purpose code value" + prompt="Select" contentBinding="controllers.purposes" optionValuePath="content.code" optionLabelPath="content.code" @@ -83,13 +83,21 @@

Source Code

Current value: {{currentShipment.sourceCode}}

{{view Trade.Select2 - prompt="Please select source code value" + prompt="Select" contentBinding="controllers.sources" optionValuePath="content.code" optionLabelPath="content.code" valueBinding="currentShipment.sourceCode" }}
+
+

Quantity

+

Current value: {{currentShipment.quantity}}

+ {{view Ember.TextField + prompt="Please type quantity value" + valueBinding="currentShipment.quantity" + }} +
@@ -121,7 +129,7 @@
- Permit & Quantity + Permit
@@ -148,14 +156,6 @@ valueBinding="currentShipment.originPermit" }}
-
-

Quantity

-

Current value: {{currentShipment.quantity}}

- {{view Ember.TextField - prompt="Please type quantity value" - valueBinding="currentShipment.quantity" - }} -
@@ -164,7 +164,7 @@ diff --git a/app/assets/javascripts/trade/templates/search/batch_form.handlebars b/app/assets/javascripts/trade/templates/search/batch_form.handlebars index 7cf4590471..45acefe654 100644 --- a/app/assets/javascripts/trade/templates/search/batch_form.handlebars +++ b/app/assets/javascripts/trade/templates/search/batch_form.handlebars @@ -65,7 +65,7 @@

Term Code

{{view Trade.Select2 - prompt="Please select term code value" + prompt="Select" contentBinding="controllers.terms" optionValuePath="content.id" optionLabelPath="content.code" @@ -75,7 +75,7 @@

Unit Code

{{view Trade.Select2 - prompt="Please select unit code value" + prompt="Select" contentBinding="controllers.units" optionValuePath="content.id" optionLabelPath="content.code" @@ -85,7 +85,7 @@

Purpose Code

{{view Trade.Select2 - prompt="Please select purpose code value" + prompt="Select" contentBinding="controllers.purposes" optionValuePath="content.id" optionLabelPath="content.code" @@ -95,7 +95,7 @@

Source Code

{{view Trade.Select2 - prompt="Please select source code value" + prompt="Select" contentBinding="controllers.sources" optionValuePath="content.id" optionLabelPath="content.code" @@ -153,7 +153,7 @@
diff --git a/app/assets/javascripts/trade/templates/search/shipment_form.handlebars b/app/assets/javascripts/trade/templates/search/shipment_form.handlebars index 2092374d9b..9e279bf3c6 100644 --- a/app/assets/javascripts/trade/templates/search/shipment_form.handlebars +++ b/app/assets/javascripts/trade/templates/search/shipment_form.handlebars @@ -13,7 +13,7 @@
- Name, Appendix and Year + Name, Appendix And Year
@@ -66,13 +66,13 @@
- Trade Codes + Trade Codes And Quantity

Term Code {{currentShipment.errors.termId}}

{{view Trade.Select2 - prompt="Please select term code value" + prompt="Select" contentBinding="controllers.terms" optionValuePath="content.id" optionLabelPath="content.code" @@ -82,7 +82,7 @@

Unit Code {{currentShipment.errors.unitId}}

{{view Trade.Select2 - prompt="Please select unit code value" + prompt="Select" contentBinding="controllers.units" optionValuePath="content.id" optionLabelPath="content.code" @@ -92,7 +92,7 @@

Purpose Code {{currentShipment.errors.purposeId}}

{{view Trade.Select2 - prompt="Please select purpose code value" + prompt="Select" contentBinding="controllers.purposes" optionValuePath="content.id" optionLabelPath="content.code" @@ -102,13 +102,20 @@

Source Code {{currentShipment.errors.sourceId}}

{{view Trade.Select2 - prompt="Please select source code value" + prompt="Select" contentBinding="controllers.sources" optionValuePath="content.id" optionLabelPath="content.code" selectionBinding="currentShipment.source" }}
+
+

Quantity {{currentShipment.errors.quantity}}

+ {{view Ember.TextField + prompt="Please type quantity value" + valueBinding="currentShipment.quantity" + }} +
@@ -156,7 +163,7 @@
- Permit & Quantity + Permit
@@ -180,13 +187,6 @@ valueBinding="currentShipment.originPermitNumber" }}
-
-

Quantity {{currentShipment.errors.quantity}}

- {{view Ember.TextField - prompt="Please type quantity value" - valueBinding="currentShipment.quantity" - }} -
@@ -197,7 +197,7 @@ needsConfirmationBinding="currentShipment.warningsConfirmation" ignoreWarningBinding="currentShipment.ignoreWarnings" }} - {{#if currentShipment.warningsPresent}} diff --git a/app/assets/stylesheets/trade/shipments.scss b/app/assets/stylesheets/trade/shipments.scss index e26d5ff757..16e4abbd95 100644 --- a/app/assets/stylesheets/trade/shipments.scss +++ b/app/assets/stylesheets/trade/shipments.scss @@ -10,6 +10,18 @@ $light-blue: #00a2db; $link-blue: #0088cc; $warning-yellow: #c09853; +/* full_screen modal window */ +.modal.shipment-form-modal.fade.in, .modal.batch-form-modal.fade.in{ + top: 0; + left: 0; + width: 99%; + height: 99%; + margin-left: 0; + .modal-body.filters { + max-height: 80%; + } +} + .modal { /* new custom width */ width: 940px; From 39e6a76e6a0b038c9bf417b2e8316fda3ccb1864 Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Mon, 26 Jan 2015 12:05:11 +0000 Subject: [PATCH 31/65] minor wording tweak --- .../annual_report_upload/sandbox_shipment_form.handlebars | 4 ++-- .../trade/templates/search/shipment_form.handlebars | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/trade/templates/annual_report_upload/sandbox_shipment_form.handlebars b/app/assets/javascripts/trade/templates/annual_report_upload/sandbox_shipment_form.handlebars index f48d478d7f..82d8635184 100644 --- a/app/assets/javascripts/trade/templates/annual_report_upload/sandbox_shipment_form.handlebars +++ b/app/assets/javascripts/trade/templates/annual_report_upload/sandbox_shipment_form.handlebars @@ -8,7 +8,7 @@
- Name, Appendix and Year + Name, Appendix & Year
@@ -43,7 +43,7 @@
- Trade Codes And Quantity + Trade Codes & Quantity
diff --git a/app/assets/javascripts/trade/templates/search/shipment_form.handlebars b/app/assets/javascripts/trade/templates/search/shipment_form.handlebars index 9e279bf3c6..50b58583d5 100644 --- a/app/assets/javascripts/trade/templates/search/shipment_form.handlebars +++ b/app/assets/javascripts/trade/templates/search/shipment_form.handlebars @@ -13,7 +13,7 @@
- Name, Appendix And Year + Name, Appendix & Year
@@ -66,7 +66,7 @@
- Trade Codes And Quantity + Trade Codes & Quantity
From 0ccd3b508cabe976e7d059f9273ed27d7e1e3b16 Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Fri, 23 Jan 2015 14:38:05 +0000 Subject: [PATCH 32/65] added ability to bulk update shipments with blank value for non-required fields --- .../search_results_controller.js.coffee | 6 ++- .../models/shipment_batch_update.js.coffee | 46 +++++++++++++++---- .../templates/search/batch_form.handlebars | 44 ++++++++++++++++++ app/assets/stylesheets/trade/shipments.scss | 4 ++ app/controllers/trade/shipments_controller.rb | 13 +++--- app/models/trade/batch_update.rb | 1 + 6 files changed, 99 insertions(+), 15 deletions(-) diff --git a/app/assets/javascripts/trade/controllers/search_results_controller.js.coffee b/app/assets/javascripts/trade/controllers/search_results_controller.js.coffee index a672839eb2..40b12cdd0a 100644 --- a/app/assets/javascripts/trade/controllers/search_results_controller.js.coffee +++ b/app/assets/javascripts/trade/controllers/search_results_controller.js.coffee @@ -161,13 +161,17 @@ Trade.SearchResultsController = Ember.ArrayController.extend Trade.QueryParams, ) updateBatch: -> + updates = @get('batchUpdateParams').export() + if Object.keys(updates).length == 0 + alert("No changes detected.") + return false if confirm("This will update " + @get('total') + " shipments. Are you sure?") $.ajax( url: '/trade/shipments/update_batch' type: 'POST' data: filters: @get('controllers.search.searchParams') - updates: @get('batchUpdateParams').export() + updates: updates ) .done( (data) => @flashSuccess(message: 'Successfully updated ' + data.rows + ' shipments.') diff --git a/app/assets/javascripts/trade/models/shipment_batch_update.js.coffee b/app/assets/javascripts/trade/models/shipment_batch_update.js.coffee index 28dd81cfae..8550db7e49 100644 --- a/app/assets/javascripts/trade/models/shipment_batch_update.js.coffee +++ b/app/assets/javascripts/trade/models/shipment_batch_update.js.coffee @@ -11,12 +11,37 @@ Trade.ShipmentBatchUpdate = Ember.Object.extend exporter: null countryOfOrigin: null reporterType: null + importPermitNumber: null + exportPermitNumber: null + originPermitNumber: null + countryOfOriginBlank: false + unitBlank: false + sourceBlank: false + purposeBlank: false + importPermitNumberBlank: false + exportPermitNumberBlank: false + originPermitNumberBlank: false columns: (-> [ 'taxonConceptId', 'reportedTaxonConceptId', 'appendix', 'year', 'term', 'unit', 'purpose', 'source', - 'importer', 'exporter', 'countryOfOrigin', 'reporterType' + 'importer', 'exporter', 'countryOfOrigin', 'reporterType', + 'importPermitNumber', 'exportPermitNumber', 'originPermitNumber' + ] + ).property() + + nullableColumns: (-> + [ + 'countryOfOrigin', 'unit', 'source', 'purpose', + 'importPermitNumber', 'exportPermitNumber', 'originPermitNumber' + ] + ).property() + + columnsToExportAsIds: (-> + [ + 'term', 'unit', 'purpose', 'source', + 'importer', 'exporter', 'countryOfOrigin' ] ).property() @@ -28,13 +53,18 @@ Trade.ShipmentBatchUpdate = Ember.Object.extend export: -> result = {} @get('columns').forEach( (c) => - property_value = @get(c) - if property_value - property_name = c.decamelize() - if typeof property_value == 'object' - result[property_name + '_id'] = property_value.get('id') - else - result[property_name] = property_value + propertyValue = @get(c) + propertyNameForBackend = c.decamelize() + if @get('columnsToExportAsIds').contains(c) + propertyNameForBackend += '_id' + if propertyValue + if @get('columnsToExportAsIds').contains(c) + propertyValue = propertyValue.get('id') + result[propertyNameForBackend] = propertyValue + if @get('nullableColumns').contains(c) + blankPropertyName = c + 'Blank' + if @get(blankPropertyName) + result[propertyNameForBackend] = null ) result diff --git a/app/assets/javascripts/trade/templates/search/batch_form.handlebars b/app/assets/javascripts/trade/templates/search/batch_form.handlebars index 45acefe654..c58b83d09d 100644 --- a/app/assets/javascripts/trade/templates/search/batch_form.handlebars +++ b/app/assets/javascripts/trade/templates/search/batch_form.handlebars @@ -81,6 +81,10 @@ optionLabelPath="content.code" selectionBinding="currentShipment.unit" }} +

Purpose Code

@@ -91,6 +95,10 @@ optionLabelPath="content.code" selectionBinding="currentShipment.purpose" }} +

Source Code

@@ -101,6 +109,10 @@ optionLabelPath="content.code" selectionBinding="currentShipment.source" }} +
@@ -137,6 +149,10 @@ optionLabelPath="content.name" selectionBinding="currentShipment.countryOfOrigin" }} +

Reporter type

@@ -148,6 +164,34 @@
+
+ Permit numbers +
+
+
+

Import Permit

+ +
+
+

Exporter Permit

+ +
+
+

Origin Permit

+ +
+
+ +
diff --git a/app/assets/stylesheets/trade/shipments.scss b/app/assets/stylesheets/trade/shipments.scss index 16e4abbd95..89bdedd4bc 100644 --- a/app/assets/stylesheets/trade/shipments.scss +++ b/app/assets/stylesheets/trade/shipments.scss @@ -289,6 +289,10 @@ div.popup-holder01 { input { width: 175px; } + input[type="checkbox"] { + width: 50px; + margin: 0; + } select { width: 190px; margin: 0; diff --git a/app/controllers/trade/shipments_controller.rb b/app/controllers/trade/shipments_controller.rb index a00dbc14d2..2ed6f96eac 100644 --- a/app/controllers/trade/shipments_controller.rb +++ b/app/controllers/trade/shipments_controller.rb @@ -71,25 +71,26 @@ def shipment_attributes :country_of_origin_id, :purpose_id, :source_id, - :year + :year, + :import_permit_number, + :export_permit_number, + :origin_permit_number ] end def shipment_params params.require(:shipment).permit( *(shipment_attributes + [ - :import_permit_number, - :export_permit_number, - :origin_permit_number, :ignore_warnings ]) ) end def batch_update_params - res = params.permit( + update_params = params.permit( :updates => shipment_attributes - ).delete(:updates) + ) + res = update_params && update_params.delete('updates') || {} reporter_type = res.delete(:reporter_type) unless reporter_type.blank? res[:reported_by_exporter] = Trade::Shipment.reporter_type_to_reported_by_exporter(reporter_type) diff --git a/app/models/trade/batch_update.rb b/app/models/trade/batch_update.rb index 85431d7dc4..c8bf8c99aa 100644 --- a/app/models/trade/batch_update.rb +++ b/app/models/trade/batch_update.rb @@ -13,6 +13,7 @@ def initialize(search_params) end def execute(update_params) + return 0 unless update_params.keys.size > 0 affected_shipments = nil Trade::Shipment.transaction do affected_shipments = @shipments.count From d821d7836d973319702056dfce95cc7b87b21459 Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Fri, 23 Jan 2015 21:21:30 +0000 Subject: [PATCH 33/65] fixed blank updates for column types where null value is required rather than empty string --- app/controllers/trade/shipments_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/trade/shipments_controller.rb b/app/controllers/trade/shipments_controller.rb index 2ed6f96eac..dde38ab0de 100644 --- a/app/controllers/trade/shipments_controller.rb +++ b/app/controllers/trade/shipments_controller.rb @@ -91,6 +91,7 @@ def batch_update_params :updates => shipment_attributes ) res = update_params && update_params.delete('updates') || {} + res.each { |k, v| res[k] = nil if v.blank? } reporter_type = res.delete(:reporter_type) unless reporter_type.blank? res[:reported_by_exporter] = Trade::Shipment.reporter_type_to_reported_by_exporter(reporter_type) From 38266c4d22fb7767d9c81933d47ffd0029124fff Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Mon, 26 Jan 2015 15:34:54 +0000 Subject: [PATCH 34/65] task to populate terminating suspension regulations --- ...uspensions_to_terminating_regulations.rake | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 lib/tasks/map_eu_suspensions_to_terminating_regulations.rake diff --git a/lib/tasks/map_eu_suspensions_to_terminating_regulations.rake b/lib/tasks/map_eu_suspensions_to_terminating_regulations.rake new file mode 100644 index 0000000000..3d417ed871 --- /dev/null +++ b/lib/tasks/map_eu_suspensions_to_terminating_regulations.rake @@ -0,0 +1,22 @@ +task :map_eu_suspensions_to_terminating_regulations => :environment do + update_query = <<-SQL + WITH suspension_regulations AS ( + SELECT events1.id, events1.name, events1.effective_at, events2.id AS end_event_id, events2.name, events2.effective_at + FROM events events1 + JOIN events events2 + ON events1.type = events2.type AND events1.end_date = events2.effective_at + WHERE events1.type = 'EuSuspensionRegulation' + ), eu_suspensions_without_end_event AS ( + SELECT * + FROM eu_decisions + WHERE type = 'EuSuspension' AND end_event_id IS NULL AND NOT is_current + ) + UPDATE eu_decisions + SET end_event_id = suspension_regulations.end_event_id + FROM suspension_regulations + WHERE suspension_regulations.id = eu_decisions.start_event_id + RETURNING *; + SQL + res = ActiveRecord::Base.connection.execute update_query + puts "#{res.cmd_tuples()} rows linked to terminating EU Suspension Regulations" +end From 62e9f96fcb8c945e1718c84decce0bb57692002a Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Mon, 26 Jan 2015 15:35:35 +0000 Subject: [PATCH 35/65] simplification of the EU suspension regulation applicability view --- ...plify_eu_suspensions_applicability_view.rb | 13 +++++ .../20150126135438.sql | 47 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 db/migrate/20150126135438_simplify_eu_suspensions_applicability_view.rb create mode 100644 db/views/eu_suspensions_applicability_view/20150126135438.sql diff --git a/db/migrate/20150126135438_simplify_eu_suspensions_applicability_view.rb b/db/migrate/20150126135438_simplify_eu_suspensions_applicability_view.rb new file mode 100644 index 0000000000..8df7ee2ee7 --- /dev/null +++ b/db/migrate/20150126135438_simplify_eu_suspensions_applicability_view.rb @@ -0,0 +1,13 @@ +class SimplifyEuSuspensionsApplicabilityView < ActiveRecord::Migration + def up + execute "DROP VIEW IF EXISTS eu_suspensions_applicability_view CASCADE" + execute "CREATE VIEW eu_suspensions_applicability_view AS #{view_sql('20150126135438', 'eu_suspensions_applicability_view')}" + execute "CREATE VIEW eu_decisions_view AS #{view_sql('20150122132408', 'eu_decisions_view')}" + end + + def down + execute "DROP VIEW IF EXISTS eu_suspensions_applicability_view CASCADE" + execute "CREATE VIEW eu_suspensions_applicability_view AS #{view_sql('20150121234014', 'eu_suspensions_applicability_view')}" + execute "CREATE VIEW eu_decisions_view AS #{view_sql('20150122132408', 'eu_decisions_view')}" + end +end diff --git a/db/views/eu_suspensions_applicability_view/20150126135438.sql b/db/views/eu_suspensions_applicability_view/20150126135438.sql new file mode 100644 index 0000000000..f578bedfdf --- /dev/null +++ b/db/views/eu_suspensions_applicability_view/20150126135438.sql @@ -0,0 +1,47 @@ +WITH RECURSIVE eu_decisions_with_end_dates AS ( + SELECT + eu_decisions.id, + taxon_concept_id, + geo_entity_id, + term_id, + source_id, + start_event.effective_at AS start_event_date, + end_event.effective_at AS end_event_date + FROM eu_decisions + JOIN events AS start_event ON start_event.id = eu_decisions.start_event_id + LEFT JOIN events AS end_event ON end_event.id = eu_decisions.end_event_id + WHERE eu_decisions.type = 'EuSuspension' +), eu_decisions_chain AS ( + SELECT eu_decisions_with_end_dates.*, eu_decisions_with_end_dates.start_event_date AS new_start_event_date + FROM eu_decisions_with_end_dates + WHERE end_event_date IS NULL + + UNION + + SELECT eu_decisions_chain.id, + eu_decisions_chain.taxon_concept_id, + eu_decisions_chain.geo_entity_id, + eu_decisions_chain.term_id, + eu_decisions_chain.source_id, + eu_decisions_chain.start_event_date, + eu_decisions_chain.end_event_date, + eu_decisions_with_end_dates.start_event_date + FROM eu_decisions_chain + JOIN eu_decisions_with_end_dates + ON eu_decisions_chain.taxon_concept_id = eu_decisions_with_end_dates.taxon_concept_id + AND eu_decisions_chain.geo_entity_id = eu_decisions_with_end_dates.geo_entity_id + AND ( + eu_decisions_chain.term_id = eu_decisions_with_end_dates.term_id + OR eu_decisions_chain.term_id IS NULL AND eu_decisions_with_end_dates.term_id IS NULL + ) + AND ( + eu_decisions_chain.source_id = eu_decisions_with_end_dates.source_id + OR eu_decisions_chain.source_id IS NULL AND eu_decisions_with_end_dates.source_id IS NULL + ) + AND eu_decisions_chain.new_start_event_date = eu_decisions_with_end_dates.end_event_date +) +SELECT +id, +MIN(new_start_event_date) AS original_start_date, +TO_CHAR(MIN(new_start_event_date), 'DD/MM/YYYY') AS original_start_date_formatted +FROM eu_decisions_chain GROUP BY id; From 2775ec34cfc8200b2f844d938ecb12053fd5bc3d Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Mon, 26 Jan 2015 13:37:43 +0000 Subject: [PATCH 36/65] Added dependents_updated_at field to internal downloads --- .../species/orphaned_taxon_concepts_export.rb | 5 +- .../synonyms_and_trade_names_export.rb | 5 +- .../species/taxon_concepts_names_export.rb | 5 +- ...t_to_taxon_concepts_views_for_downloads.rb | 19 ++++++ .../20150126125749.sql | 46 +++++++++++++++ .../20150126125749.sql | 58 +++++++++++++++++++ .../20150126125749.sql | 46 +++++++++++++++ .../orphaned_taxon_concepts/.gitkeep | 0 8 files changed, 178 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20150126125749_add_dependents_updated_at_to_taxon_concepts_views_for_downloads.rb create mode 100644 db/views/orphaned_taxon_concepts_view/20150126125749.sql create mode 100644 db/views/synonyms_and_trade_names_view/20150126125749.sql create mode 100644 db/views/taxon_concepts_names_view/20150126125749.sql create mode 100644 public/downloads/orphaned_taxon_concepts/.gitkeep diff --git a/app/models/species/orphaned_taxon_concepts_export.rb b/app/models/species/orphaned_taxon_concepts_export.rb index 0501964439..7351083430 100644 --- a/app/models/species/orphaned_taxon_concepts_export.rb +++ b/app/models/species/orphaned_taxon_concepts_export.rb @@ -21,7 +21,7 @@ def sql_columns columns = [ :id, :legacy_id, :full_name, :author_year, :rank_name, :name_status, :taxonomy_name, :internal_notes, - :created_at, :created_by, :updated_at, :updated_by + :created_at, :created_by, :updated_at, :dependents_updated_at, :updated_by ] end @@ -29,7 +29,8 @@ def csv_column_headers headers = [ 'Id', 'Legacy id', 'Scientific Name', 'Author', 'Rank', 'Name status', 'Taxonomy', 'Internal notes', - 'Date added', 'Added by', 'Date updated', 'Updated by' + 'Date added', 'Added by', 'Taxon Concept updated date', + 'Taxon Concept associations updated date', 'Updated by' ] end diff --git a/app/models/species/synonyms_and_trade_names_export.rb b/app/models/species/synonyms_and_trade_names_export.rb index 8d6d80d3e6..f8fcd22108 100644 --- a/app/models/species/synonyms_and_trade_names_export.rb +++ b/app/models/species/synonyms_and_trade_names_export.rb @@ -26,7 +26,7 @@ def sql_columns :accepted_kingdom_name, :accepted_phylum_name, :accepted_class_name, :accepted_order_name, :accepted_family_name, :accepted_genus_name, :taxonomy_name, :internal_notes, - :created_at, :created_by, :updated_at, :updated_by + :created_at, :created_by, :updated_at, :dependents_updated_at, :updated_by ] end @@ -39,7 +39,8 @@ def csv_column_headers 'Kingdom_Accepted', 'Phylum_Accepted', 'Class_Accepted', 'Order_Accepted', 'Family_Accepted', 'Genus_Accepted', 'Taxonomy', 'Internal notes', - 'Date added', 'Added by', 'Date updated', 'Updated by' + 'Date added', 'Added by', 'Taxon Concept updated date', + 'Taxon Concept associations updated date', 'Updated by' ] end diff --git a/app/models/species/taxon_concepts_names_export.rb b/app/models/species/taxon_concepts_names_export.rb index 56a588043f..7c55ce6b1c 100644 --- a/app/models/species/taxon_concepts_names_export.rb +++ b/app/models/species/taxon_concepts_names_export.rb @@ -22,7 +22,7 @@ def sql_columns :id, :legacy_id, :kingdom_name, :phylum_name, :class_name, :order_name, :family_name, :genus_name, :species_name, :full_name, :author_year, :rank_name, :name_status, :taxonomy_name, :internal_notes, - :created_at, :created_by, :updated_at, :updated_by + :created_at, :created_by, :updated_at, :dependents_updated_at, :updated_by ] end @@ -31,7 +31,8 @@ def csv_column_headers 'Id', 'Legacy id', 'Kingdom', 'Phylum', 'Class', 'Order', 'Family', 'Genus', 'Species', 'Scientific Name', 'Author', 'Rank', 'Name status', 'Taxonomy', 'Internal notes', - 'Date added', 'Added by', 'Date updated', 'Updated by' + 'Date added', 'Added by', 'Taxon Concept updated date', + 'Taxon Concept associations updated date', 'Updated by' ] end diff --git a/db/migrate/20150126125749_add_dependents_updated_at_to_taxon_concepts_views_for_downloads.rb b/db/migrate/20150126125749_add_dependents_updated_at_to_taxon_concepts_views_for_downloads.rb new file mode 100644 index 0000000000..83b0306395 --- /dev/null +++ b/db/migrate/20150126125749_add_dependents_updated_at_to_taxon_concepts_views_for_downloads.rb @@ -0,0 +1,19 @@ +class AddDependentsUpdatedAtToTaxonConceptsViewsForDownloads < ActiveRecord::Migration + def up + execute "DROP VIEW IF EXISTS taxon_concepts_names_view" + execute "CREATE VIEW taxon_concepts_names_view AS #{view_sql('20150126125749', 'taxon_concepts_names_view')}" + execute "DROP VIEW IF EXISTS synonyms_and_trade_names_view" + execute "CREATE VIEW synonyms_and_trade_names_view AS #{view_sql('20150126125749', 'synonyms_and_trade_names_view')}" + execute "DROP VIEW IF EXISTS orphaned_taxon_concepts_view" + execute "CREATE VIEW orphaned_taxon_concepts_view AS #{view_sql('20150126125749', 'orphaned_taxon_concepts_view')}" + end + + def down + execute "DROP VIEW IF EXISTS taxon_concepts_names_view" + execute "CREATE VIEW taxon_concepts_names_view AS #{view_sql('20141223141125', 'taxon_concepts_names_view')}" + execute "DROP VIEW IF EXISTS synonyms_and_trade_names_view" + execute "CREATE VIEW synonyms_and_trade_names_view AS #{view_sql('20141223141125', 'synonyms_and_trade_names_view')}" + execute "DROP VIEW IF EXISTS orphaned_taxon_concepts_view" + execute "CREATE VIEW orphaned_taxon_concepts_view AS #{view_sql('20141223141125', 'orphaned_taxon_concepts_view')}" + end +end diff --git a/db/views/orphaned_taxon_concepts_view/20150126125749.sql b/db/views/orphaned_taxon_concepts_view/20150126125749.sql new file mode 100644 index 0000000000..bbe9c429d8 --- /dev/null +++ b/db/views/orphaned_taxon_concepts_view/20150126125749.sql @@ -0,0 +1,46 @@ +SELECT + tc.name_status, + tc.id, + tc.legacy_id, + tc.legacy_trade_code, + tc.data->'rank_name' AS rank_name, + tc.full_name, + tc.author_year, + taxonomies.id AS taxonomy_id, + taxonomies.name AS taxonomy_name, + ARRAY_TO_STRING( + ARRAY[ + general_note.note, + nomenclature_note.note, + distribution_note.note + ], + E'\n' + ) AS internal_notes, + to_char(tc.created_at, 'DD/MM/YYYY') AS created_at, + uc.name AS created_by, + to_char(tc.updated_at, 'DD/MM/YYYY') AS updated_at, + uu.name AS updated_by, + to_char(tc.dependents_updated_at, 'DD/MM/YYYY') AS dependents_updated_at +FROM taxon_concepts tc +JOIN taxonomies ON taxonomies.id = tc.taxonomy_id +LEFT JOIN taxon_relationships tr1 ON tr1.taxon_concept_id = tc.id +LEFT JOIN taxon_relationships tr2 ON tr2.other_taxon_concept_id = tc.id +LEFT JOIN taxon_concepts children ON children.parent_id = tc.id +LEFT JOIN comments general_note + ON general_note.commentable_id = tc.id + AND general_note.commentable_type = 'TaxonConcept' + AND general_note.comment_type = 'General' +LEFT JOIN comments nomenclature_note + ON nomenclature_note.commentable_id = tc.id + AND nomenclature_note.commentable_type = 'TaxonConcept' + AND nomenclature_note.comment_type = 'Nomenclature' +LEFT JOIN comments distribution_note + ON distribution_note.commentable_id = tc.id + AND distribution_note.commentable_type = 'TaxonConcept' + AND distribution_note.comment_type = 'Distribution' +LEFT JOIN users uc ON tc.created_by_id = uc.id +LEFT JOIN users uu ON tc.updated_by_id = uu.id +WHERE tc.parent_id IS NULL + AND tr1.id IS NULL + AND tr2.id IS NULL + AND children.id IS NULL; diff --git a/db/views/synonyms_and_trade_names_view/20150126125749.sql b/db/views/synonyms_and_trade_names_view/20150126125749.sql new file mode 100644 index 0000000000..57c1f8ee6f --- /dev/null +++ b/db/views/synonyms_and_trade_names_view/20150126125749.sql @@ -0,0 +1,58 @@ +SELECT + st.name_status, + st.id, + st.legacy_id, + st.legacy_trade_code, + st.data->'rank_name' AS rank_name, + st.full_name, + st.author_year, + a.full_name AS accepted_full_name, + a.author_year AS accepted_author_year, + a.id AS accepted_id, + a.data->'rank_name' AS accepted_rank_name, + a.name_status AS accepted_name_status, + a.data->'kingdom_name' AS accepted_kingdom_name, + a.data->'phylum_name' AS accepted_phylum_name, + a.data->'class_name' AS accepted_class_name, + a.data->'order_name' AS accepted_order_name, + a.data->'family_name' AS accepted_family_name, + a.data->'genus_name' AS accepted_genus_name, + a.data->'species_name' AS accepted_species_name, + taxonomies.id AS taxonomy_id, + taxonomies.name AS taxonomy_name, + ARRAY_TO_STRING( + ARRAY[ + general_note.note, + nomenclature_note.note, + distribution_note.note + ], + E'\n' + ) AS internal_notes, + to_char(st.created_at, 'DD/MM/YYYY') AS created_at, + uc.name AS created_by, + to_char(st.updated_at, 'DD/MM/YYYY') AS updated_at, + uu.name AS updated_by, + to_char(st.dependents_updated_at, 'DD/MM/YYYY') AS dependents_updated_at +FROM taxon_concepts st +JOIN taxonomies ON taxonomies.id = st.taxonomy_id +LEFT JOIN taxon_relationships +ON taxon_relationships.other_taxon_concept_id = st.id +LEFT JOIN taxon_concepts a +ON taxon_relationships.taxon_concept_id = a.id +LEFT JOIN comments general_note + ON general_note.commentable_id = st.id + AND general_note.commentable_type = 'TaxonConcept' + AND general_note.comment_type = 'General' +LEFT JOIN comments nomenclature_note + ON nomenclature_note.commentable_id = st.id + AND nomenclature_note.commentable_type = 'TaxonConcept' + AND nomenclature_note.comment_type = 'Nomenclature' +LEFT JOIN comments distribution_note + ON distribution_note.commentable_id = st.id + AND distribution_note.commentable_type = 'TaxonConcept' + AND distribution_note.comment_type = 'Distribution' +LEFT JOIN users uc +ON st.created_by_id = uc.id +LEFT JOIN users uu +ON st.updated_by_id = uu.id +WHERE st.name_status IN ('S', 'T'); diff --git a/db/views/taxon_concepts_names_view/20150126125749.sql b/db/views/taxon_concepts_names_view/20150126125749.sql new file mode 100644 index 0000000000..625330f6e5 --- /dev/null +++ b/db/views/taxon_concepts_names_view/20150126125749.sql @@ -0,0 +1,46 @@ +SELECT + taxon_concepts.id, + legacy_id, + data->'kingdom_name' AS kingdom_name, + data->'phylum_name' AS phylum_name, + data->'class_name' AS class_name, + data->'order_name' AS order_name, + data->'family_name' AS family_name, + data->'genus_name' AS genus_name, + data->'species_name' AS species_name, + full_name, + author_year, + data->'rank_name' AS rank_name, + name_status, + taxonomic_position, + taxonomy_id, + taxonomies.name AS taxonomy_name, + ARRAY_TO_STRING( + ARRAY[ + general_note.note, + nomenclature_note.note, + distribution_note.note + ], + E'\n' + ) AS internal_notes, + to_char(taxon_concepts.created_at, 'DD/MM/YYYY') AS created_at, + uc.name AS created_by, + to_char(taxon_concepts.updated_at, 'DD/MM/YYYY') AS updated_at, + uu.name AS updated_by, + to_char(taxon_concepts.dependents_updated_at, 'DD/MM/YYYY') AS dependents_updated_at +FROM taxon_concepts +JOIN taxonomies ON taxonomies.id = taxon_concepts.taxonomy_id +LEFT JOIN comments general_note + ON general_note.commentable_id = taxon_concepts.id + AND general_note.commentable_type = 'TaxonConcept' + AND general_note.comment_type = 'General' +LEFT JOIN comments nomenclature_note + ON nomenclature_note.commentable_id = taxon_concepts.id + AND nomenclature_note.commentable_type = 'TaxonConcept' + AND nomenclature_note.comment_type = 'Nomenclature' +LEFT JOIN comments distribution_note + ON distribution_note.commentable_id = taxon_concepts.id + AND distribution_note.commentable_type = 'TaxonConcept' + AND distribution_note.comment_type = 'Distribution' +LEFT JOIN users uc ON taxon_concepts.created_by_id = uc.id +LEFT JOIN users uu ON taxon_concepts.updated_by_id = uu.id; diff --git a/public/downloads/orphaned_taxon_concepts/.gitkeep b/public/downloads/orphaned_taxon_concepts/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 From 73c90244d013b66aae96fa6587ebf9c9e4073b5b Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Mon, 26 Jan 2015 13:45:07 +0000 Subject: [PATCH 37/65] Fixed alignment --- ...pendents_updated_at_to_taxon_concepts_views_for_downloads.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20150126125749_add_dependents_updated_at_to_taxon_concepts_views_for_downloads.rb b/db/migrate/20150126125749_add_dependents_updated_at_to_taxon_concepts_views_for_downloads.rb index 83b0306395..a19400bde8 100644 --- a/db/migrate/20150126125749_add_dependents_updated_at_to_taxon_concepts_views_for_downloads.rb +++ b/db/migrate/20150126125749_add_dependents_updated_at_to_taxon_concepts_views_for_downloads.rb @@ -1,5 +1,5 @@ class AddDependentsUpdatedAtToTaxonConceptsViewsForDownloads < ActiveRecord::Migration - def up + def up execute "DROP VIEW IF EXISTS taxon_concepts_names_view" execute "CREATE VIEW taxon_concepts_names_view AS #{view_sql('20150126125749', 'taxon_concepts_names_view')}" execute "DROP VIEW IF EXISTS synonyms_and_trade_names_view" From a63f428d5261dadfd5668cd53023d6eaadcb1185 Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Wed, 4 Feb 2015 21:21:58 +0000 Subject: [PATCH 38/65] [Fixes #80439442] reset 'set blank' checkboxes --- .../javascripts/trade/models/shipment_batch_update.js.coffee | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/assets/javascripts/trade/models/shipment_batch_update.js.coffee b/app/assets/javascripts/trade/models/shipment_batch_update.js.coffee index 8550db7e49..d19269461b 100644 --- a/app/assets/javascripts/trade/models/shipment_batch_update.js.coffee +++ b/app/assets/javascripts/trade/models/shipment_batch_update.js.coffee @@ -48,6 +48,9 @@ Trade.ShipmentBatchUpdate = Ember.Object.extend reset: -> @get('columns').forEach( (c) => @set(c, null) + if @get('nullableColumns').contains(c) + blankPropertyName = c + 'Blank' + @set(blankPropertyName, false) ) export: -> From bbbd665a65da245ba4485b5393795effed0de63e Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Tue, 10 Feb 2015 21:49:09 +0000 Subject: [PATCH 39/65] fix EU Suspension start dates in CSV download --- ..._suspension_start_dates_in_csv_download.rb | 6 ++ db/views/eu_decisions_view/20150210140508.sql | 95 +++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 db/migrate/20150210140508_fix_eu_suspension_start_dates_in_csv_download.rb create mode 100644 db/views/eu_decisions_view/20150210140508.sql diff --git a/db/migrate/20150210140508_fix_eu_suspension_start_dates_in_csv_download.rb b/db/migrate/20150210140508_fix_eu_suspension_start_dates_in_csv_download.rb new file mode 100644 index 0000000000..2d70f5c820 --- /dev/null +++ b/db/migrate/20150210140508_fix_eu_suspension_start_dates_in_csv_download.rb @@ -0,0 +1,6 @@ +class FixEuSuspensionStartDatesInCsvDownload < ActiveRecord::Migration + def change + execute "DROP VIEW IF EXISTS eu_decisions_view" + execute "CREATE VIEW eu_decisions_view AS #{view_sql('20150210140508', 'eu_decisions_view')}" + end +end diff --git a/db/views/eu_decisions_view/20150210140508.sql b/db/views/eu_decisions_view/20150210140508.sql new file mode 100644 index 0000000000..60d889fa03 --- /dev/null +++ b/db/views/eu_decisions_view/20150210140508.sql @@ -0,0 +1,95 @@ +SELECT + taxon_concept_id, + taxon_concepts.taxonomic_position, + (taxon_concepts.data->'kingdom_id')::INT AS kingdom_id, + (taxon_concepts.data->'phylum_id')::INT AS phylum_id, + (taxon_concepts.data->'class_id')::INT AS class_id, + (taxon_concepts.data->'order_id')::INT AS order_id, + (taxon_concepts.data->'family_id')::INT AS family_id, + taxon_concepts.data->'kingdom_name' AS kingdom_name, + taxon_concepts.data->'phylum_name' AS phylum_name, + taxon_concepts.data->'class_name' AS class_name, + taxon_concepts.data->'order_name' AS order_name, + taxon_concepts.data->'family_name' AS family_name, + taxon_concepts.data->'genus_name' AS genus_name, + LOWER(taxon_concepts.data->'species_name') AS species_name, + LOWER(taxon_concepts.data->'subspecies_name') AS subspecies_name, + taxon_concepts.full_name AS full_name, + taxon_concepts.data->'rank_name' AS rank_name, + CASE + WHEN eu_decisions.type::text = 'EuOpinion'::text THEN eu_decisions.start_date::date + WHEN eu_decisions.type::text = 'EuSuspension'::text THEN start_event.effective_at::date + ELSE NULL::date + END AS start_date, + to_char( + CASE + WHEN eu_decisions.type::text = 'EuOpinion'::text THEN eu_decisions.start_date::date + WHEN eu_decisions.type::text = 'EuSuspension'::text THEN start_event.effective_at::date + ELSE NULL::date + END::timestamp with time zone, + 'DD/MM/YYYY'::text + ) AS start_date_formatted, + t.original_start_date, + TO_CHAR(t.original_start_date, 'DD/MM/YYYY') AS original_start_date_formatted, + geo_entity_id, + geo_entities.name_en AS party, + CASE + WHEN eu_decision_types.name ~* '^i+\)' + THEN '(No opinion) ' || eu_decision_types.name + ELSE eu_decision_types.name + END AS decision_type_for_display, + eu_decision_types.decision_type AS decision_type, + sources.name_en AS source_name, + sources.code || ' - ' || sources.name_en AS source_code_and_name, + terms.name_en AS term_name, + eu_decisions.notes, + start_event.name AS start_event_name, + CASE + WHEN ( + eu_decisions.type = 'EuOpinion' AND eu_decisions.is_current + ) + OR ( + eu_decisions.type = 'EuSuspension' + AND start_event.effective_at < current_date + AND start_event.is_current = true + AND (eu_decisions.end_event_id IS NULL OR end_event.effective_at > current_date) + ) + THEN TRUE + ELSE FALSE + END AS is_valid, + CASE + WHEN ( + eu_decisions.type = 'EuOpinion' AND eu_decisions.is_current + ) + OR ( + eu_decisions.type = 'EuSuspension' + AND start_event.effective_at < current_date + AND start_event.is_current = true + AND (eu_decisions.end_event_id IS NULL OR end_event.effective_at > current_date) + ) + THEN 'Valid' + ELSE 'Not Valid' + END AS is_valid_for_display, + CASE + WHEN eu_decisions.type = 'EuOpinion' + THEN eu_decisions.start_date + WHEN eu_decisions.type = 'EuSuspension' + THEN start_event.effective_at + END AS ordering_date, + CASE + WHEN LENGTH(eu_decisions.notes) > 0 THEN strip_tags(eu_decisions.notes) + ELSE '' + END + || CASE + WHEN LENGTH(eu_decisions.nomenclature_note_en) > 0 THEN E'\n' || strip_tags(eu_decisions.nomenclature_note_en) + ELSE '' + END AS full_note_en +FROM eu_decisions +JOIN eu_decision_types ON eu_decision_types.id = eu_decisions.eu_decision_type_id +JOIN taxon_concepts ON taxon_concepts.id = eu_decisions.taxon_concept_id +LEFT JOIN events AS start_event ON start_event.id = eu_decisions.start_event_id +LEFT JOIN events AS end_event ON end_event.id = eu_decisions.end_event_id +LEFT JOIN geo_entities ON geo_entities.id = eu_decisions.geo_entity_id +LEFT JOIN trade_codes sources ON sources.type = 'Source' AND sources.id = eu_decisions.source_id +LEFT JOIN trade_codes terms ON terms.type = 'Term' AND terms.id = eu_decisions.term_id +LEFT JOIN eu_suspensions_applicability_view t ON t.id = eu_decisions.id; From 75a6816edba11f50867a294ee281c73a3eb23ac3 Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Tue, 10 Feb 2015 22:23:12 +0000 Subject: [PATCH 40/65] fix for display of subspecies quotas, suspensions & decisions --- .../species/show_taxon_concept_serializer.rb | 16 ++++++++-------- .../show_taxon_concept_serializer_cites.rb | 12 ++++++------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/serializers/species/show_taxon_concept_serializer.rb b/app/serializers/species/show_taxon_concept_serializer.rb index 716efb5546..92a510d0ec 100644 --- a/app/serializers/species/show_taxon_concept_serializer.rb +++ b/app/serializers/species/show_taxon_concept_serializer.rb @@ -53,16 +53,16 @@ def synonyms end def object_and_children - [object.id]+object.children.select(:id).map(&:id) + [object.id] + object.children.pluck(:id) end - def children_and_ancestors - ids = object.children.select(:id).map(&:id)+ - [object.data['kingdom_id'], object.data['phylum_id'], - object.data['order_id'], object.data['class_id'], - object.data['family_id'], object.data['subfamily_id'], - object.data['genus_id']] - ids.reject{|r| r.nil?} #remove nils + def ancestors + [ + object.data['kingdom_id'], object.data['phylum_id'], + object.data['order_id'], object.data['class_id'], + object.data['family_id'], object.data['subfamily_id'], + object.data['genus_id'] + ].compact end def common_names diff --git a/app/serializers/species/show_taxon_concept_serializer_cites.rb b/app/serializers/species/show_taxon_concept_serializer_cites.rb index 8350575df8..0b90560925 100644 --- a/app/serializers/species/show_taxon_concept_serializer_cites.rb +++ b/app/serializers/species/show_taxon_concept_serializer_cites.rb @@ -12,12 +12,12 @@ class Species::ShowTaxonConceptSerializerCites < Species::ShowTaxonConceptSerial def quotas Quota.from('api_cites_quotas_view trade_restrictions'). where(" - trade_restrictions.taxon_concept_id = ? + trade_restrictions.taxon_concept_id IN (?) OR ( (trade_restrictions.taxon_concept_id IN (?) OR trade_restrictions.taxon_concept_id IS NULL) AND matching_taxon_concept_ids @> ARRAY[?]::INT[] ) - ", object.id, children_and_ancestors, object.id). + ", object_and_children, ancestors, object.id). select(<<-SQL trade_restrictions.notes, trade_restrictions.url, @@ -52,12 +52,12 @@ def quotas def cites_suspensions CitesSuspension.from('api_cites_suspensions_view trade_restrictions'). where(" - trade_restrictions.taxon_concept_id = ? + trade_restrictions.taxon_concept_id IN (?) OR ( (trade_restrictions.taxon_concept_id IN (?) OR trade_restrictions.taxon_concept_id IS NULL) AND matching_taxon_concept_ids @> ARRAY[?]::INT[] ) - ", object.id, children_and_ancestors, object.id). + ", object_and_children, ancestors, object.id). select(<<-SQL trade_restrictions.notes, trade_restrictions.start_date, @@ -90,13 +90,13 @@ def cites_suspensions def eu_decisions EuDecision.from('api_eu_decisions_view eu_decisions'). where(" - eu_decisions.taxon_concept_id = ? + eu_decisions.taxon_concept_id IN (?) OR ( eu_decisions.taxon_concept_id IN (?) AND eu_decisions.geo_entity_id IN (SELECT geo_entity_id FROM distributions WHERE distributions.taxon_concept_id = ?) ) - ", object.id, children_and_ancestors, object.id). + ", object_and_children, ancestors, object.id). select(<<-SQL eu_decisions.notes, eu_decisions.start_date, From e05b89e61ab034188d645f7d4dc7d6a34018bc90 Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Tue, 17 Feb 2015 18:16:48 +0000 Subject: [PATCH 41/65] fixed inherited reference flag --- .../taxon_concept_references/_list.html.erb | 2 +- ...concept_id_to_api_taxon_references_view.rb | 11 ++++ .../20150217174539.sql | 61 +++++++++++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20150217174539_add_original_taxon_concept_id_to_api_taxon_references_view.rb create mode 100644 db/views/api_taxon_references_view/20150217174539.sql diff --git a/app/views/admin/taxon_concept_references/_list.html.erb b/app/views/admin/taxon_concept_references/_list.html.erb index a2f392c439..9a9541a243 100644 --- a/app/views/admin/taxon_concept_references/_list.html.erb +++ b/app/views/admin/taxon_concept_references/_list.html.erb @@ -25,7 +25,7 @@ - <%= true_false_icon(taxon_reference.taxon_concept_id != @taxon_concept.id) %> + <%= true_false_icon(taxon_reference['original_taxon_concept_id'] != @taxon_concept.id) %> <% unless taxon_reference.taxon_concept_id == @taxon_concept.id %> (<%= link_to taxon_reference.taxon_concept.full_name, admin_taxon_concept_taxon_concept_references_url(taxon_reference.taxon_concept) %>) diff --git a/db/migrate/20150217174539_add_original_taxon_concept_id_to_api_taxon_references_view.rb b/db/migrate/20150217174539_add_original_taxon_concept_id_to_api_taxon_references_view.rb new file mode 100644 index 0000000000..7c14495489 --- /dev/null +++ b/db/migrate/20150217174539_add_original_taxon_concept_id_to_api_taxon_references_view.rb @@ -0,0 +1,11 @@ +class AddOriginalTaxonConceptIdToApiTaxonReferencesView < ActiveRecord::Migration + def up + execute "DROP VIEW IF EXISTS api_taxon_references_view" + execute "CREATE VIEW api_taxon_references_view AS #{view_sql('20150217174539', 'api_taxon_references_view')}" + end + + def down + execute "DROP VIEW IF EXISTS api_taxon_references_view" + execute "CREATE VIEW api_taxon_references_view AS #{view_sql('20150106100040', 'api_taxon_references_view')}" + end +end diff --git a/db/views/api_taxon_references_view/20150217174539.sql b/db/views/api_taxon_references_view/20150217174539.sql new file mode 100644 index 0000000000..867b124bf7 --- /dev/null +++ b/db/views/api_taxon_references_view/20150217174539.sql @@ -0,0 +1,61 @@ +WITH RECURSIVE all_tc_refs AS ( + SELECT + id, + taxon_concept_id AS original_taxon_concept_id, + taxon_concept_id, + reference_id, + excluded_taxon_concepts_ids AS exclusions, + is_cascaded, + is_standard + FROM taxon_concept_references + + UNION + + SELECT + h.id, + h.original_taxon_concept_id, + hi.id, + h.reference_id, + h.exclusions, + h.is_cascaded, + h.is_standard + FROM taxon_concepts hi + JOIN all_tc_refs h + ON h.taxon_concept_id = hi.parent_id + AND NOT COALESCE(h.exclusions, ARRAY[]::INT[]) @> ARRAY[hi.id] + AND h.is_cascaded + AND h.is_standard +) +SELECT + all_tc_refs.id, + all_tc_refs.taxon_concept_id, + all_tc_refs.reference_id, + all_tc_refs.is_standard, + refs.citation +FROM all_tc_refs +JOIN "references" refs ON refs.id = all_tc_refs.reference_id; + +-- A more efficient approach that could also be used in other places: +-- cites_eu_taxon_concepts_and_ancestors_mview is currently created as a temp table +-- as part of the rebuild script +-- WITH all_tc_refs AS ( +-- SELECT +-- tcr.id, +-- tcr.reference_id, +-- tcr.excluded_taxon_concepts_ids AS exclusions, +-- tcr.is_cascaded, +-- tcr.is_standard, +-- t.taxon_concept_id +-- FROM taxon_concept_references tcr +-- JOIN cites_eu_taxon_concepts_and_ancestors_mview t +-- ON t.ancestor_taxon_concept_id = tcr.taxon_concept_id +-- WHERE NOT COALESCE(tcr.excluded_taxon_concepts_ids, ARRAY[]::INT[]) @> ARRAY[t.taxon_concept_id] +-- ) +-- SELECT +-- all_tc_refs.id, +-- all_tc_refs.taxon_concept_id, +-- all_tc_refs.reference_id, +-- all_tc_refs.is_standard, +-- refs.citation +-- FROM all_tc_refs +-- JOIN "references" refs ON refs.id = all_tc_refs.reference_id From 9487b122e12b60bb200080bb211bb7ebd56334f4 Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Wed, 25 Feb 2015 10:13:39 +0000 Subject: [PATCH 42/65] removed permits cache, as it is good for nothing --- app/controllers/trade/permits_controller.rb | 2 -- app/sweepers/permit_sweeper.rb | 21 --------------------- 2 files changed, 23 deletions(-) delete mode 100644 app/sweepers/permit_sweeper.rb diff --git a/app/controllers/trade/permits_controller.rb b/app/controllers/trade/permits_controller.rb index f967d91164..a994ed3233 100644 --- a/app/controllers/trade/permits_controller.rb +++ b/app/controllers/trade/permits_controller.rb @@ -1,6 +1,4 @@ class Trade::PermitsController < TradeController - caches_action :index, :cache_path => Proc.new { |c| c.params } - cache_sweeper :permit_sweeper def index matcher = Trade::PermitMatcher.new(params) diff --git a/app/sweepers/permit_sweeper.rb b/app/sweepers/permit_sweeper.rb deleted file mode 100644 index f233da0c59..0000000000 --- a/app/sweepers/permit_sweeper.rb +++ /dev/null @@ -1,21 +0,0 @@ -class PermitSweeper < ActionController::Caching::Sweeper - observe Trade::Permit - - def after_create(tc) - expire_cache(tc) - end - - def after_update(tc) - expire_cache(tc) - end - - def after_destroy(tc) - expire_cache(tc) - end - - private - - def expire_cache(tc) - expire_action(:controller => "api/v1/permits", :action => "index") - end -end From 5918b4f23415bc3334c67fd61e3b6d92761865ed Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Wed, 25 Feb 2015 13:59:13 +0000 Subject: [PATCH 43/65] remove unused permits --- .../20150225102903_remove_unused_permits.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 db/migrate/20150225102903_remove_unused_permits.rb diff --git a/db/migrate/20150225102903_remove_unused_permits.rb b/db/migrate/20150225102903_remove_unused_permits.rb new file mode 100644 index 0000000000..9becc179d1 --- /dev/null +++ b/db/migrate/20150225102903_remove_unused_permits.rb @@ -0,0 +1,17 @@ +class RemoveUnusedPermits < ActiveRecord::Migration + def up + execute <<-SQL + WITH unused_permits(id) AS ( + SELECT id FROM trade_permits + EXCEPT + SELECT UNNEST(import_permits_ids || export_permits_ids || origin_permits_ids) FROM trade_shipments + ) + DELETE FROM trade_permits + USING unused_permits + WHERE trade_permits.id = unused_permits.id; + SQL + end + + def down + end +end From bf28d44f8d5d5a97d979a312aaf9ebed9cfcf68d Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Wed, 25 Feb 2015 22:08:19 +0000 Subject: [PATCH 44/65] remove orphaned permits after updating / deleting shipments --- app/controllers/trade/shipments_controller.rb | 13 ++++++ app/models/trade/batch_update.rb | 4 ++ app/models/trade/shipment.rb | 12 ++++-- app/models/trade/shipment_observer.rb | 22 ++++++++++ app/workers/permit_cleanup_worker.rb | 26 +++++++++++ .../trade/shipments_controller_spec.rb | 43 ++++++++++++++++++- spec/spec_helper.rb | 17 ++++++++ 7 files changed, 133 insertions(+), 4 deletions(-) create mode 100644 app/workers/permit_cleanup_worker.rb diff --git a/app/controllers/trade/shipments_controller.rb b/app/controllers/trade/shipments_controller.rb index dde38ab0de..3f094a9392 100644 --- a/app/controllers/trade/shipments_controller.rb +++ b/app/controllers/trade/shipments_controller.rb @@ -44,7 +44,11 @@ def destroy def destroy_batch @search = Trade::Filter.new(search_params) cnt = @search.query.count + disconnected_permits_ids = @search.query.map do |s| + s.permits_ids + end.flatten.uniq @search.query.destroy_all + PermitCleanupWorker.perform_async(disconnected_permits_ids) render :json => {rows: cnt}, :status => :ok end @@ -96,6 +100,15 @@ def batch_update_params unless reporter_type.blank? res[:reported_by_exporter] = Trade::Shipment.reporter_type_to_reported_by_exporter(reporter_type) end + if res.has_key?(:import_permit_number) && res[:import_permit_number].nil? + res[:import_permits_ids] = nil + end + if res.has_key?(:export_permit_number) && res[:export_permit_number].nil? + res[:export_permits_ids] = nil + end + if res.has_key?(:origin_permit_number) && res[:origin_permit_number].nil? + res[:origin_permits_ids] = nil + end res end diff --git a/app/models/trade/batch_update.rb b/app/models/trade/batch_update.rb index c8bf8c99aa..c829076af7 100644 --- a/app/models/trade/batch_update.rb +++ b/app/models/trade/batch_update.rb @@ -14,12 +14,16 @@ def initialize(search_params) def execute(update_params) return 0 unless update_params.keys.size > 0 + disconnected_permits_ids = @shipments.map do |s| + s.permits_ids + end.flatten.uniq affected_shipments = nil Trade::Shipment.transaction do affected_shipments = @shipments.count @shipments.update_all(update_params) DownloadsCache.clear_shipments end + PermitCleanupWorker.perform_async(disconnected_permits_ids) affected_shipments end diff --git a/app/models/trade/shipment.rb b/app/models/trade/shipment.rb index 5859d491dc..11c93492cc 100644 --- a/app/models/trade/shipment.rb +++ b/app/models/trade/shipment.rb @@ -113,7 +113,7 @@ def origin_permit_number=(str) end def import_permits_ids - parse_pg_array(read_attribute(:import_permits_ids)) + parse_pg_array(read_attribute(:import_permits_ids) || '') end def import_permits_ids=(ary) @@ -121,7 +121,7 @@ def import_permits_ids=(ary) end def export_permits_ids - parse_pg_array(read_attribute(:export_permits_ids)) + parse_pg_array(read_attribute(:export_permits_ids) || '') end def export_permits_ids=(ary) @@ -129,13 +129,19 @@ def export_permits_ids=(ary) end def origin_permits_ids - parse_pg_array(read_attribute(:origin_permits_ids)) + parse_pg_array(read_attribute(:origin_permits_ids) || '') end def origin_permits_ids=(ary) write_attribute(:origin_permits_ids, "{#{ary && ary.join(',')}}") end + def permits_ids + ( + import_permits_ids + export_permits_ids + origin_permits_ids + ).uniq.compact + end + private # note: this updates the precomputed fields diff --git a/app/models/trade/shipment_observer.rb b/app/models/trade/shipment_observer.rb index d9c8d8187f..f7f4dc7849 100644 --- a/app/models/trade/shipment_observer.rb +++ b/app/models/trade/shipment_observer.rb @@ -1,17 +1,39 @@ class Trade::ShipmentObserver < ActiveRecord::Observer + include PgArrayParser def before_save(shipment) + @old_permits_ids = [] + [ + shipment.import_permits_ids_was, + shipment.export_permits_ids_was, + shipment.origin_permits_ids_was + ].each do |permits_ids| + # no idea why this is sometimes a string and sometimes an Array + @old_permits_ids += if permits_ids.is_a?(Array) + permits_ids.dup + else + parse_pg_array(permits_ids || '') + end + end unless shipment.reported_taxon_concept_id shipment.reported_taxon_concept_id = shipment.taxon_concept_id end end + def before_destroy(shipment) + @old_permits_ids = shipment.permits_ids.dup + end + def after_save(shipment) DownloadsCache.clear_shipments + disconnected_permits_ids = @old_permits_ids - shipment.permits_ids + PermitCleanupWorker.perform_async(disconnected_permits_ids) end def after_destroy(shipment) DownloadsCache.clear_shipments + disconnected_permits_ids = @old_permits_ids + PermitCleanupWorker.perform_async(disconnected_permits_ids) end end \ No newline at end of file diff --git a/app/workers/permit_cleanup_worker.rb b/app/workers/permit_cleanup_worker.rb new file mode 100644 index 0000000000..bb9feffa8e --- /dev/null +++ b/app/workers/permit_cleanup_worker.rb @@ -0,0 +1,26 @@ +class PermitCleanupWorker + include Sidekiq::Worker + sidekiq_options :queue => :admin,:backtrace => 50 + + def perform(permits_ids=[]) + return if permits_ids.empty? + sql = <<-SQL + WITH unused_permits(id) AS ( + SELECT id FROM trade_permits WHERE id IN (:permits_ids) + EXCEPT + SELECT UNNEST(import_permits_ids || export_permits_ids || origin_permits_ids) + FROM trade_shipments + WHERE import_permits_ids @> ARRAY[:permits_ids] OR + export_permits_ids @> ARRAY[:permits_ids] OR + origin_permits_ids @> ARRAY[:permits_ids] + ) + DELETE FROM trade_permits + USING unused_permits + WHERE trade_permits.id = unused_permits.id + SQL + ActiveRecord::Base.connection.execute( + ActiveRecord::Base.send(:sanitize_sql_array, [sql, + permits_ids: permits_ids.map(&:to_i) + ])) + end +end diff --git a/spec/controllers/trade/shipments_controller_spec.rb b/spec/controllers/trade/shipments_controller_spec.rb index 4c84f344ad..b2d374881e 100644 --- a/spec/controllers/trade/shipments_controller_spec.rb +++ b/spec/controllers/trade/shipments_controller_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Trade::ShipmentsController do +describe Trade::ShipmentsController, sidekiq: :inline do login_admin include_context 'Shipments' @@ -40,6 +40,13 @@ } @shipment1.reload.taxon_concept_id.should == @animal_species.id end + it "should delete orphaned permits" do + put :update, id: @shipment1.id, + shipment: { + import_permit_number: 'YYY' + } + Trade::Permit.find_by_id(@import_permit.id).should be_nil + end end describe "POST update_batch" do @@ -129,6 +136,24 @@ @shipment1.reload.taxon_concept_id.should == @animal_species.id end + it "should set permit number to blank and delete orphaned permits" do + post :update_batch, { + filters: { # shipment1 + time_range_start: @shipment1.year, + time_range_end: @shipment2.year, + year: 2013, + exporters_ids: [@portugal.id.to_s, @argentina.id.to_s], + importers_ids: [@portugal.id.to_s, @argentina.id.to_s] + }, + updates: { + import_permit_number: nil + } + } + @shipment1.reload.import_permits_ids.should be_blank + @shipment1.import_permit_number.should be_nil + Trade::Permit.find_by_id(@import_permit.id).should be_nil + end + end describe "POST destroy_batch" do @@ -194,7 +219,19 @@ post :destroy_batch, sources_ids: [@source_wild.id.to_s], reporter_type: 'I', source_blank: "true" Trade::Shipment.count.should == 2 + end + it "should delete orphaned permits" do + post :destroy_batch, { + # shipment1 + time_range_start: @shipment1.year, + time_range_end: @shipment2.year, + year: 2013, + exporters_ids: [@portugal.id.to_s, @argentina.id.to_s], + importers_ids: [@portugal.id.to_s, @argentina.id.to_s] + } + Trade::Shipment.find_by_id(@shipment1.id).should be_nil + Trade::Permit.find_by_id(@import_permit.id).should be_nil end end @@ -204,5 +241,9 @@ delete :destroy, id: @shipment1.id Trade::Shipment.where(id: @shipment1.id).should be_empty end + it "should delete orphaned permits" do + delete :destroy, id: @shipment1.id + Trade::Permit.find_by_id(@import_permit.id).should be_nil + end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index bf6e407c51..a63a717013 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -79,6 +79,23 @@ @user.make_current end + config.before(:each) do |example_method| + # Clears out the jobs for tests using the fake testing + Sidekiq::Worker.clear_all + # Get the current example from the example_method object + example = example_method.example + + if example.metadata[:sidekiq] == :fake + Sidekiq::Testing.fake! + elsif example.metadata[:sidekiq] == :inline + Sidekiq::Testing.inline! + elsif example.metadata[:type] == :feature + Sidekiq::Testing.inline! + else + Sidekiq::Testing.fake! + end + end + end def build_attributes(*args) From 83d6967dbcacae982e5d1aa5b49a66c1ce132521 Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Wed, 25 Feb 2015 23:29:05 +0000 Subject: [PATCH 45/65] convert permit numbers to upper case and ensure matching on number considers case --- app/models/trade/shipment.rb | 2 +- ...011_copy_transactions_from_sandbox_to_shipments.sql | 10 +++++----- spec/models/trade/annual_report_upload_spec.rb | 2 +- spec/models/trade/shipment_spec.rb | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/models/trade/shipment.rb b/app/models/trade/shipment.rb index 11c93492cc..5d4e6bbdaf 100644 --- a/app/models/trade/shipment.rb +++ b/app/models/trade/shipment.rb @@ -149,7 +149,7 @@ def permits_ids # (import_permit_number=, export_permit_number=, origin_permit_number=) def set_permit_number(permit_type, str) permits = str && str.split(';').compact.map do |number| - Trade::Permit.find_or_create_by_number(number.strip) + Trade::Permit.find_or_create_by_number(number.strip.upcase) end # save the concatenated permit numbers in the precomputed field write_attribute("#{permit_type}_permit_number", permits && permits.map(&:number).join(';')) diff --git a/db/plpgsql/011_copy_transactions_from_sandbox_to_shipments.sql b/db/plpgsql/011_copy_transactions_from_sandbox_to_shipments.sql index 661b91e184..a2b8d2b0b0 100644 --- a/db/plpgsql/011_copy_transactions_from_sandbox_to_shipments.sql +++ b/db/plpgsql/011_copy_transactions_from_sandbox_to_shipments.sql @@ -131,12 +131,12 @@ BEGIN SQUISH(regexp_split_to_table(origin_permit, ''[:;,]'')) AS permit FROM '|| table_name || ' ), permits_to_be_inserted (number) AS ( - SELECT DISTINCT permit FROM split_permits WHERE permit IS NOT NULL + SELECT DISTINCT UPPER(permit) FROM split_permits WHERE permit IS NOT NULL EXCEPT - SELECT number FROM trade_permits + SELECT UPPER(number) FROM trade_permits ) INSERT INTO trade_permits(number, created_at, updated_at) - SELECT number, current_timestamp, current_timestamp + SELECT UPPER(number), current_timestamp, current_timestamp FROM permits_to_be_inserted'; EXECUTE sql; @@ -242,7 +242,7 @@ BEGIN INNER JOIN split_permits ON split_permits.id = shipments_for_submit.sandbox_id INNER JOIN trade_permits - ON trade_permits.number = split_permits.permit + ON UPPER(trade_permits.number) = UPPER(split_permits.permit) ), agg_shipment_permits AS ( SELECT trade_shipment_id, ARRAY_AGG(trade_permit_id) AS permits_ids, @@ -251,7 +251,7 @@ BEGIN GROUP BY trade_shipment_id ) UPDATE trade_shipments - SET ' || permit_type || '_permit_number = sp.permit_number, + SET ' || permit_type || '_permit_number = UPPER(sp.permit_number), ' || permit_type || '_permits_ids = sp.permits_ids FROM agg_shipment_permits sp WHERE sp.trade_shipment_id = trade_shipments.id; diff --git a/spec/models/trade/annual_report_upload_spec.rb b/spec/models/trade/annual_report_upload_spec.rb index b6843868bc..af2b5f1048 100644 --- a/spec/models/trade/annual_report_upload_spec.rb +++ b/spec/models/trade/annual_report_upload_spec.rb @@ -180,7 +180,7 @@ def invalid_file subject.submit; Trade::Permit.find_by_number('BBB').should_not be_nil } context "when permit previously reported" do - before(:each) { create(:permit, :number => 'XXX') } + before(:each) { create(:permit, :number => 'xxx') } specify { expect{subject.submit}.to change{Trade::Permit.count}.by(2) } diff --git a/spec/models/trade/shipment_spec.rb b/spec/models/trade/shipment_spec.rb index 6659ae83e6..c4931b0eef 100644 --- a/spec/models/trade/shipment_spec.rb +++ b/spec/models/trade/shipment_spec.rb @@ -57,13 +57,13 @@ ) end context "when export permit" do - specify { @shipment.export_permit_number.should == 'a' } + specify { @shipment.export_permit_number.should == 'A' } end context "when import permit" do - specify { @shipment.import_permit_number.should == 'b' } + specify { @shipment.import_permit_number.should == 'B' } end context "when origin permit" do - specify { @shipment.origin_permit_number.should == 'c' } + specify { @shipment.origin_permit_number.should == 'C' } end end end From f6fc7637308dd028dc603a07c9d02a3669213c36 Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Wed, 25 Feb 2015 23:30:23 +0000 Subject: [PATCH 46/65] removed obsolete file --- db/plpgsql/012_rebuild_permit_numbers.sql | 1 - 1 file changed, 1 deletion(-) delete mode 100644 db/plpgsql/012_rebuild_permit_numbers.sql diff --git a/db/plpgsql/012_rebuild_permit_numbers.sql b/db/plpgsql/012_rebuild_permit_numbers.sql deleted file mode 100644 index 6f2479dc9d..0000000000 --- a/db/plpgsql/012_rebuild_permit_numbers.sql +++ /dev/null @@ -1 +0,0 @@ -DROP FUNCTION IF EXISTS rebuild_permit_numbers(); \ No newline at end of file From c7986b83394444d48e2b978ab97b8e87dc45da0a Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Wed, 25 Feb 2015 23:42:43 +0000 Subject: [PATCH 47/65] clean downloads cache in a background job --- app/models/cites_suspension_observer.rb | 2 +- app/models/eu_decision_observer.rb | 2 +- app/models/quota_observer.rb | 2 +- app/models/taxon_concept_observer.rb | 4 ++-- app/models/trade/annual_report_upload.rb | 2 +- app/models/trade/batch_update.rb | 2 +- app/models/trade/shipment_observer.rb | 4 ++-- app/models/trade/trade_data_download_observer.rb | 2 +- app/workers/downloads_cache_cleanup_worker.rb | 8 ++++++++ 9 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 app/workers/downloads_cache_cleanup_worker.rb diff --git a/app/models/cites_suspension_observer.rb b/app/models/cites_suspension_observer.rb index 3a355e7cfb..e37b283794 100644 --- a/app/models/cites_suspension_observer.rb +++ b/app/models/cites_suspension_observer.rb @@ -16,7 +16,7 @@ def after_destroy(cites_suspension) else touch_taxa_with_applicable_distribution(cites_suspension) end - DownloadsCache.clear_cites_suspensions + DownloadsCacheCleanupWorker.perform_async(:cites_suspensions) end def touch_taxa_with_applicable_distribution(cites_suspension) diff --git a/app/models/eu_decision_observer.rb b/app/models/eu_decision_observer.rb index 8aa1af8aba..ffc16c388c 100644 --- a/app/models/eu_decision_observer.rb +++ b/app/models/eu_decision_observer.rb @@ -1,7 +1,7 @@ class EuDecisionObserver < ActiveRecord::Observer def after_destroy(eu_decision) - DownloadsCache.clear_eu_decisions + DownloadsCacheCleanupWorker.perform_async(:eu_decisions) end end \ No newline at end of file diff --git a/app/models/quota_observer.rb b/app/models/quota_observer.rb index 960a7625d7..cf520d7fc6 100644 --- a/app/models/quota_observer.rb +++ b/app/models/quota_observer.rb @@ -1,7 +1,7 @@ class QuotaObserver < ActiveRecord::Observer def after_destroy(quota) - DownloadsCache.clear_quotas + DownloadsCacheCleanupWorker.perform_async(:quotas) end end \ No newline at end of file diff --git a/app/models/taxon_concept_observer.rb b/app/models/taxon_concept_observer.rb index b2e99b63a2..f4fc6d32ed 100644 --- a/app/models/taxon_concept_observer.rb +++ b/app/models/taxon_concept_observer.rb @@ -71,11 +71,11 @@ def ensure_species_touched(taxon_concept) end def after_save(taxon_concept) - DownloadsCache.clear_taxon_concepts + DownloadsCacheCleanupWorker.perform_async(:taxon_concepts) end def after_destroy(taxon_concept) - DownloadsCache.clear_taxon_concepts + DownloadsCacheCleanupWorker.perform_async(:taxon_concepts) end end diff --git a/app/models/trade/annual_report_upload.rb b/app/models/trade/annual_report_upload.rb index bb9d75ef43..7735f35d2a 100644 --- a/app/models/trade/annual_report_upload.rb +++ b/app/models/trade/annual_report_upload.rb @@ -85,7 +85,7 @@ def submit sandbox.destroy #clear downloads cache - DownloadsCache.clear_shipments + DownloadsCacheCleanupWorker.perform_async(:shipments) #flag as submitted update_attribute(:is_done, true) diff --git a/app/models/trade/batch_update.rb b/app/models/trade/batch_update.rb index c829076af7..6026aba0f4 100644 --- a/app/models/trade/batch_update.rb +++ b/app/models/trade/batch_update.rb @@ -21,7 +21,7 @@ def execute(update_params) Trade::Shipment.transaction do affected_shipments = @shipments.count @shipments.update_all(update_params) - DownloadsCache.clear_shipments + DownloadsCacheCleanupWorker.perform_async(:shipments) end PermitCleanupWorker.perform_async(disconnected_permits_ids) affected_shipments diff --git a/app/models/trade/shipment_observer.rb b/app/models/trade/shipment_observer.rb index f7f4dc7849..ddc0621d6e 100644 --- a/app/models/trade/shipment_observer.rb +++ b/app/models/trade/shipment_observer.rb @@ -25,13 +25,13 @@ def before_destroy(shipment) end def after_save(shipment) - DownloadsCache.clear_shipments + DownloadsCacheCleanupWorker.perform_async(:shipments) disconnected_permits_ids = @old_permits_ids - shipment.permits_ids PermitCleanupWorker.perform_async(disconnected_permits_ids) end def after_destroy(shipment) - DownloadsCache.clear_shipments + DownloadsCacheCleanupWorker.perform_async(:shipments) disconnected_permits_ids = @old_permits_ids PermitCleanupWorker.perform_async(disconnected_permits_ids) end diff --git a/app/models/trade/trade_data_download_observer.rb b/app/models/trade/trade_data_download_observer.rb index 3050504b1a..682579fb92 100644 --- a/app/models/trade/trade_data_download_observer.rb +++ b/app/models/trade/trade_data_download_observer.rb @@ -1,7 +1,7 @@ class Trade::TradeDataDownloadObserver < ActiveRecord::Observer def after_save(download_log) - DownloadsCache.clear_trade_download_stats + DownloadsCacheCleanupWorker.perform_async(:trade_download_stats) end end \ No newline at end of file diff --git a/app/workers/downloads_cache_cleanup_worker.rb b/app/workers/downloads_cache_cleanup_worker.rb new file mode 100644 index 0000000000..a259a27716 --- /dev/null +++ b/app/workers/downloads_cache_cleanup_worker.rb @@ -0,0 +1,8 @@ +class DownloadsCacheCleanupWorker + include Sidekiq::Worker + sidekiq_options :queue => :admin,:backtrace => 50 + + def perform(type_of_cache) + DownloadsCache.send(:"clear_#{type_of_cache}") + end +end From d9e102447a2300c2d2ba991a7339db6c1b1074ac Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Thu, 26 Feb 2015 13:51:36 +0000 Subject: [PATCH 48/65] fixed the inherited reference flag again --- app/views/admin/taxon_concept_references/_list.html.erb | 2 +- db/views/api_taxon_references_view/20150217174539.sql | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/admin/taxon_concept_references/_list.html.erb b/app/views/admin/taxon_concept_references/_list.html.erb index 9a9541a243..acf841054e 100644 --- a/app/views/admin/taxon_concept_references/_list.html.erb +++ b/app/views/admin/taxon_concept_references/_list.html.erb @@ -25,7 +25,7 @@ - <%= true_false_icon(taxon_reference['original_taxon_concept_id'] != @taxon_concept.id) %> + <%= true_false_icon(taxon_reference['original_taxon_concept_id'].try(:to_i) != @taxon_concept.id) %> <% unless taxon_reference.taxon_concept_id == @taxon_concept.id %> (<%= link_to taxon_reference.taxon_concept.full_name, admin_taxon_concept_taxon_concept_references_url(taxon_reference.taxon_concept) %>) diff --git a/db/views/api_taxon_references_view/20150217174539.sql b/db/views/api_taxon_references_view/20150217174539.sql index 867b124bf7..10a710061d 100644 --- a/db/views/api_taxon_references_view/20150217174539.sql +++ b/db/views/api_taxon_references_view/20150217174539.sql @@ -29,6 +29,7 @@ WITH RECURSIVE all_tc_refs AS ( SELECT all_tc_refs.id, all_tc_refs.taxon_concept_id, + all_tc_refs.original_taxon_concept_id, all_tc_refs.reference_id, all_tc_refs.is_standard, refs.citation From b843cf44a2095b38a738b6e4fe558c4b60756507 Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Mon, 2 Mar 2015 08:27:03 +0000 Subject: [PATCH 49/65] fix for 0 excluded taxon concepts in view --- .../taxon_concept_references/_list.html.erb | 2 +- ...ncepts_ids_to_api_taxon_references_view.rb | 11 ++++ .../20150302082111.sql | 63 +++++++++++++++++++ 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20150302082111_add_excluded_taxon_concepts_ids_to_api_taxon_references_view.rb create mode 100644 db/views/api_taxon_references_view/20150302082111.sql diff --git a/app/views/admin/taxon_concept_references/_list.html.erb b/app/views/admin/taxon_concept_references/_list.html.erb index acf841054e..847ac74ba0 100644 --- a/app/views/admin/taxon_concept_references/_list.html.erb +++ b/app/views/admin/taxon_concept_references/_list.html.erb @@ -21,7 +21,7 @@ - <%= taxon_reference.excluded_taxon_concepts.count %> + <%= taxon_reference.excluded_taxon_concepts_ids.length %> diff --git a/db/migrate/20150302082111_add_excluded_taxon_concepts_ids_to_api_taxon_references_view.rb b/db/migrate/20150302082111_add_excluded_taxon_concepts_ids_to_api_taxon_references_view.rb new file mode 100644 index 0000000000..20b1c037f6 --- /dev/null +++ b/db/migrate/20150302082111_add_excluded_taxon_concepts_ids_to_api_taxon_references_view.rb @@ -0,0 +1,11 @@ +class AddExcludedTaxonConceptsIdsToApiTaxonReferencesView < ActiveRecord::Migration + def up + execute "DROP VIEW IF EXISTS api_taxon_references_view" + execute "CREATE VIEW api_taxon_references_view AS #{view_sql('20150302082111', 'api_taxon_references_view')}" + end + + def down + execute "DROP VIEW IF EXISTS api_taxon_references_view" + execute "CREATE VIEW api_taxon_references_view AS #{view_sql('20150217174539', 'api_taxon_references_view')}" + end +end diff --git a/db/views/api_taxon_references_view/20150302082111.sql b/db/views/api_taxon_references_view/20150302082111.sql new file mode 100644 index 0000000000..4ead4857fa --- /dev/null +++ b/db/views/api_taxon_references_view/20150302082111.sql @@ -0,0 +1,63 @@ +WITH RECURSIVE all_tc_refs AS ( + SELECT + id, + taxon_concept_id AS original_taxon_concept_id, + taxon_concept_id, + reference_id, + excluded_taxon_concepts_ids, + is_cascaded, + is_standard + FROM taxon_concept_references + + UNION + + SELECT + h.id, + h.original_taxon_concept_id, + hi.id, + h.reference_id, + h.excluded_taxon_concepts_ids, + h.is_cascaded, + h.is_standard + FROM taxon_concepts hi + JOIN all_tc_refs h + ON h.taxon_concept_id = hi.parent_id + AND NOT COALESCE(h.excluded_taxon_concepts_ids, ARRAY[]::INT[]) @> ARRAY[hi.id] + AND h.is_cascaded + AND h.is_standard +) +SELECT + all_tc_refs.id, + all_tc_refs.taxon_concept_id, + all_tc_refs.original_taxon_concept_id, + all_tc_refs.excluded_taxon_concepts_ids, + all_tc_refs.reference_id, + all_tc_refs.is_standard, + refs.citation +FROM all_tc_refs +JOIN "references" refs ON refs.id = all_tc_refs.reference_id; + +-- A more efficient approach that could also be used in other places: +-- cites_eu_taxon_concepts_and_ancestors_mview is currently created as a temp table +-- as part of the rebuild script +-- WITH all_tc_refs AS ( +-- SELECT +-- tcr.id, +-- tcr.reference_id, +-- tcr.excluded_taxon_concepts_ids, +-- tcr.is_cascaded, +-- tcr.is_standard, +-- t.taxon_concept_id +-- FROM taxon_concept_references tcr +-- JOIN cites_eu_taxon_concepts_and_ancestors_mview t +-- ON t.ancestor_taxon_concept_id = tcr.taxon_concept_id +-- WHERE NOT COALESCE(tcr.excluded_taxon_concepts_ids, ARRAY[]::INT[]) @> ARRAY[t.taxon_concept_id] +-- ) +-- SELECT +-- all_tc_refs.id, +-- all_tc_refs.taxon_concept_id, +-- all_tc_refs.reference_id, +-- all_tc_refs.is_standard, +-- refs.citation +-- FROM all_tc_refs +-- JOIN "references" refs ON refs.id = all_tc_refs.reference_id From 5fc443f61e4d31f37dcc67a1a0b1dbe1150454be Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Mon, 9 Mar 2015 16:33:43 +0000 Subject: [PATCH 50/65] in case there is no start event --- app/views/admin/eu_opinions/_current_opinions_form.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/eu_opinions/_current_opinions_form.html.erb b/app/views/admin/eu_opinions/_current_opinions_form.html.erb index dc18767e70..e3da58b02a 100644 --- a/app/views/admin/eu_opinions/_current_opinions_form.html.erb +++ b/app/views/admin/eu_opinions/_current_opinions_form.html.erb @@ -18,7 +18,7 @@ <%= opinion.year %> - <%= opinion.start_event.name %> + <%= opinion.start_event && opinion.start_event.name %> <%= opinion.geo_entity && opinion.geo_entity.name_en %> <%= opinion.eu_decision_type.name %> From c9f7123d9bbfc9db3f5eb15a54cf5c763228db46 Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Mon, 9 Mar 2015 16:47:01 +0000 Subject: [PATCH 51/65] remove null elements --- app/models/taxon_concept_reference.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/taxon_concept_reference.rb b/app/models/taxon_concept_reference.rb index e0a49f6d83..152c793f4a 100644 --- a/app/models/taxon_concept_reference.rb +++ b/app/models/taxon_concept_reference.rb @@ -36,7 +36,7 @@ def excluded_taxon_concepts end def excluded_taxon_concepts_ids - parse_pg_array(read_attribute(:excluded_taxon_concepts_ids)||"") + parse_pg_array(read_attribute(:excluded_taxon_concepts_ids)||"").compact end def excluded_taxon_concepts_ids=(ary) From 91a156b81bcc3c0e38d3779654e48a510729a5c5 Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Mon, 9 Mar 2015 20:25:29 +0000 Subject: [PATCH 52/65] use exact ruby version to avoid issues when deploying (should be upgraded though) --- .ruby-version | 2 +- config/deploy.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.ruby-version b/.ruby-version index 227cea2156..6b751b7289 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.0.0 +2.0.0-p481 diff --git a/config/deploy.rb b/config/deploy.rb index 882587bb55..489b6b9b75 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -38,7 +38,7 @@ set :generate_webserver_config, false require 'rvm/capistrano' -set :rvm_ruby_string, '2.0.0' +set :rvm_ruby_string, 'ruby-2.0.0-p481' ssh_options[:forward_agent] = true From 10966696ab6a05cb0a8d0c66b7c8a2ab88b68944 Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Fri, 23 Jan 2015 13:46:08 +0000 Subject: [PATCH 53/65] Import and adjustments on EC SRG events --- .../admin/eu_opinions_controller.rb | 1 + app/views/admin/ec_srgs/_form.html.erb | 1 + app/views/admin/eu_opinions/_form.html.erb | 2 +- .../SRG_meetings_and_SoCs_for_IT_CSV.csv | 70 +++++++++++++++++++ lib/tasks/import_events.rake | 12 ++++ 5 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 lib/files/SRG_meetings_and_SoCs_for_IT_CSV.csv diff --git a/app/controllers/admin/eu_opinions_controller.rb b/app/controllers/admin/eu_opinions_controller.rb index 7fedc00d41..77d8a7e044 100644 --- a/app/controllers/admin/eu_opinions_controller.rb +++ b/app/controllers/admin/eu_opinions_controller.rb @@ -41,6 +41,7 @@ def load_lib_objects where(:geo_entity_types => {:name => GeoEntityType::SETS[GeoEntityType::DEFAULT_SET]}) @eu_regulations = EuRegulation.order("effective_at DESC") @eu_decision_types = EuDecisionType.opinions + @ec_srgs = EcSrg.order("effective_at DESC") end def collection diff --git a/app/views/admin/ec_srgs/_form.html.erb b/app/views/admin/ec_srgs/_form.html.erb index 7bba75c75b..e56c0cb1f6 100644 --- a/app/views/admin/ec_srgs/_form.html.erb +++ b/app/views/admin/ec_srgs/_form.html.erb @@ -8,4 +8,5 @@ <%= f.text_field :effective_at, :class => "datepicker", :value => @ec_srg.effective_at_formatted %> + <%= f.text_field :url %>
<% end %> diff --git a/app/views/admin/eu_opinions/_form.html.erb b/app/views/admin/eu_opinions/_form.html.erb index 70e76746f2..303b40aa44 100644 --- a/app/views/admin/eu_opinions/_form.html.erb +++ b/app/views/admin/eu_opinions/_form.html.erb @@ -16,7 +16,7 @@ <%= f.label :start_event_id, "Regulation", :class => 'control-label' %>
<%= f.select :start_event_id, - options_from_collection_for_select(@eu_regulations, :id, :name, @eu_opinion.start_event_id), + options_from_collection_for_select(@ec_srgs, :id, :name, @eu_opinion.start_event_id), { }, :class => "select2" %>
diff --git a/lib/files/SRG_meetings_and_SoCs_for_IT_CSV.csv b/lib/files/SRG_meetings_and_SoCs_for_IT_CSV.csv new file mode 100644 index 0000000000..63cb4f0ef7 --- /dev/null +++ b/lib/files/SRG_meetings_and_SoCs_for_IT_CSV.csv @@ -0,0 +1,70 @@ +SRG Meeting,Date,Link to SoC on CIRCABC,Created at,Updated at,Type +SRG 1,10/03/1997,,23/01/15,23/01/15,EcSrg +SRG 2,22/07/1997,,23/01/15,23/01/15,EcSrg +SRG 3,02/09/1997,,23/01/15,23/01/15,EcSrg +SRG 4,09/10/1997,,23/01/15,23/01/15,EcSrg +SRG 5,11/11/1997,,23/01/15,23/01/15,EcSrg +SRG 6,15/12/1997,,23/01/15,23/01/15,EcSrg +SRG 7,12/02/1998,,23/01/15,23/01/15,EcSrg +SRG 8,13/05/1998,,23/01/15,23/01/15,EcSrg +SRG 9,10/09/1998,,23/01/15,23/01/15,EcSrg +SRG 10,18/11/1998,,23/01/15,23/01/15,EcSrg +SRG 11,27/01/1999,,23/01/15,23/01/15,EcSrg +SRG 12,22/04/1999,,23/01/15,23/01/15,EcSrg +SRG 13,23/06/1999,,23/01/15,23/01/15,EcSrg +SRG 14,16/09/1999,,23/01/15,23/01/15,EcSrg +SRG 15,10/12/1999,,23/01/15,23/01/15,EcSrg +SRG 16,22/02/2000,,23/01/15,23/01/15,EcSrg +SRG 17,11/07/2000,https://circabc.europa.eu/sd/a/7bda20c0-a2b8-4baf-ae48-7e14f7950621/17th_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 18,07/11/2000,https://circabc.europa.eu/sd/a/0fc4643b-01b4-4450-b8e6-6b7714b0a294/18th_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 19,26/03/2001,https://circabc.europa.eu/sd/a/33519bee-64e5-40ab-8e3e-ebeaf8df8be8/19th_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 20,18/07/2001,https://circabc.europa.eu/sd/a/1bb5a9d1-4ea3-469f-ad97-893a2177a546/20th_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 21,29/11/2001,https://circabc.europa.eu/sd/a/dc92090b-44e5-409c-90cf-af7cdb884717/21th_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 22,02/04/2002,https://circabc.europa.eu/sd/a/e963caac-ef35-4e7f-a0c3-e8cb90d64a12/22nd_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 23,15/05/2002,https://circabc.europa.eu/sd/a/11e6f369-4158-4c53-b5f4-758311ea02e7/23rd_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 24,05 /09/2002,https://circabc.europa.eu/sd/a/1d82f266-6dba-49c9-ab8a-f39800e3097d/24th_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 25,30/01/2003,https://circabc.europa.eu/sd/a/71160b1b-98ec-4794-aec6-3ad91d941545/25th_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 26,22/06/2003,https://circabc.europa.eu/sd/a/16b5291a-72e1-4bd5-b4a4-97165ab1ba1a/26th_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 27,9/10/2003,https://circabc.europa.eu/sd/a/f8cb6ace-6d99-4835-96a7-b1d8106bc583/27th_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 28,15/01/2004,https://circabc.europa.eu/sd/a/c5fc6aab-7470-4c28-8752-fe1b7e940491/28th_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 29,19/04/2004,https://circabc.europa.eu/sd/a/8e8986ef-1631-45ad-840a-b6102823a19c/29th_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 30,01/07/2004,https://circabc.europa.eu/sd/a/586d627c-6bc3-4e6f-b67b-f5bb43f26121/30_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 31,13/12/2004,https://circabc.europa.eu/sd/a/e5913353-b76e-46b7-9f87-fbb52ec28733/31_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 32,15/03/2005,https://circabc.europa.eu/sd/a/0c09af3a-ab30-44a1-a9fb-5898b7df5af9/32_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 33,13/06/2005,https://circabc.europa.eu/sd/a/944a6a37-3984-4976-9692-b4556d9c0689/33_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 34,25/10/2005,https://circabc.europa.eu/sd/a/1d0e1151-4505-40bd-91dc-c3daa67ee568/34_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 35,20/12/2005,https://circabc.europa.eu/sd/a/4001443c-634d-4327-ae02-eba8e71021f8/35_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 36,09/03/2006,https://circabc.europa.eu/sd/a/f5997a71-066e-4422-947d-1cdb02b56cf5/36_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 37,12/06/2006,https://circabc.europa.eu/sd/a/f47d8e70-ae41-4089-8262-4ae7eeca3f11/37_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 38,26/09/2006,https://circabc.europa.eu/sd/a/7de62e68-cb43-403d-b1a8-49d42eceeb0d/38_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 39,18/12/2006,https://circabc.europa.eu/sd/a/a4bdcbb0-a39d-4636-b62d-12744c3ffe48/39_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 40,27/03/2007,https://circabc.europa.eu/sd/a/745de21a-5194-4885-9998-1ebbc58d085e/40_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 41,14/09/2007,https://circabc.europa.eu/sd/a/72936373-7736-4099-bab5-00caa31153c9/41_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 42,07/12/2007,https://circabc.europa.eu/sd/a/1c1797bb-8a1e-42b4-890b-fa2d96d92aa7/42_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 43,29/02/2008,https://circabc.europa.eu/sd/a/eb78b8cb-f7f8-404e-ba9c-37ed6e9eb1aa/43_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 44,26/05/2008,https://circabc.europa.eu/sd/a/bc9c10c6-aec4-432e-aa8b-0c26394d0c54/44_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 45,15/09/2008,https://circabc.europa.eu/sd/a/0df70e1c-16d3-4b07-a3e9-53e8791f97bc/45_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 46,02/12/2008,https://circabc.europa.eu/sd/a/7aadfe6e-0cda-40e9-87d1-b1779a868f16/46_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 47,12/02/2009,https://circabc.europa.eu/sd/a/74d824b6-33ff-4303-b641-68406aa8a78a/47_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 48,30/06/2009,https://circabc.europa.eu/sd/a/62d19591-bb71-4ddd-ac2e-d255f1b12508/48_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 49,11/09/2009,https://circabc.europa.eu/sd/a/e674ae4c-614e-4923-b7c0-89f6879ccbd6/49_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 50,30/11/2009,https://circabc.europa.eu/sd/a/d618137f-ace6-475c-980e-ff021304a7f9/50_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 51,16/02/2010,https://circabc.europa.eu/sd/a/be2b6893-a7a9-4121-abfa-5bdff593cfc1/51_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 52,18/05/2010,https://circabc.europa.eu/sd/a/1b94874e-1dcc-487d-b57d-548f7f2248d3/52_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 53,14/09/2010,https://circabc.europa.eu/sd/a/c07a4a45-ad49-43e8-af7d-f0d5b8b032b6/53_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 54,03/12/2010,https://circabc.europa.eu/sd/a/49ab3fc9-646b-4b35-ac42-f0333479ce24/54_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 55,11/03/2011,https://circabc.europa.eu/sd/a/438c82d2-bc33-4ce2-90b6-e229674b3cfb/55_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 56,20/06/2011,https://circabc.europa.eu/sd/a/d7af194e-57f1-4cac-9413-adb39bf19706/56_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 57,07/10/2011,https://circabc.europa.eu/sd/a/2585a880-a461-4766-b90a-b677892da05c/57_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 58,02/12/2011,https://circabc.europa.eu/sd/a/5f5b3e36-cf0d-4f09-a86d-1ac1eee2bb3c/58_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 59,23/02/2012,https://circabc.europa.eu/sd/a/1a415f3d-a6d9-45c8-ad95-0d6b20d6fc1b/59_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 60,07/06/2012,https://circabc.europa.eu/sd/a/1ea000aa-5c88-4084-9cad-38ed3132d91c/60_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 61,11/09/2012,https://circabc.europa.eu/sd/a/256747e3-c7ea-4081-acbe-e39ce14eb5bc/61_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 62,07/12/2012,https://circabc.europa.eu/sd/a/e842f212-4da4-41a9-8f62-56cd013d3f4c/62_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 63,07/02/2013,https://circabc.europa.eu/sd/a/ef09aeec-3bf8-4815-94b9-b28471cc62f1/63_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 64,28/05/2013,https://circabc.europa.eu/sd/a/d01002d3-1599-4079-bcfc-b3a2e01ab374/64_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 65,12/09/2013,https://circabc.europa.eu/sd/a/b69f4031-d07e-4960-a0a8-5aa755678dfd/65_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 66,06/12/2013,https://circabc.europa.eu/sd/a/201742b3-e7e2-40d4-86b8-963d9d04076b/66_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 67,27/02/2014,https://circabc.europa.eu/sd/a/b65b499d-4aa4-4cc1-81db-b85b2126b6cc/67_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 68,28/05/2014,https://circabc.europa.eu/sd/a/dbc2ef30-bd5c-4f42-b795-5e2735198e87/68_summary_srg.pdf ,23/01/15,23/01/15,EcSrg +SRG 69,03/09/2014,https://circabc.europa.eu/sd/a/a0c4f3e6-6862-46cb-8c95-8f7c78ff962e/69_summary_srg%20rev.pdf ,23/01/15,23/01/15,EcSrg diff --git a/lib/tasks/import_events.rake b/lib/tasks/import_events.rake index 9ac920c365..b4f5f6e511 100644 --- a/lib/tasks/import_events.rake +++ b/lib/tasks/import_events.rake @@ -34,6 +34,18 @@ namespace :import do puts "There are now #{Event.count} events in the database" end + task :ec_srg, [:file] => [:environment] do |t, args| + sql = <<-PSQL + COPY events(name,effective_at,url,created_at,updated_at,type) + FROM '#{Rails.root + args.file}' + WITH DELIMITER ',' + CSV HEADER + NULL AS ' ' + PSQL + ActiveRecord::Base.connection.execute(sql) + puts "There are now #{EcSrg.count} EcSrg events in the database" + end + task :eu_annex_regulations_end_dates => [:environment] do TMP_TABLE = "eu_annex_regulations_end_dates_import" file = "lib/files/eu_annex_regulations_end_dates_utf8.csv" From 18de08a311a66a9b58b5741fff7966bd9cc863c0 Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Fri, 23 Jan 2015 20:02:50 +0000 Subject: [PATCH 54/65] Remove unnecessary eu_regulations --- app/controllers/admin/eu_opinions_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/admin/eu_opinions_controller.rb b/app/controllers/admin/eu_opinions_controller.rb index 77d8a7e044..cc54b57b54 100644 --- a/app/controllers/admin/eu_opinions_controller.rb +++ b/app/controllers/admin/eu_opinions_controller.rb @@ -39,7 +39,6 @@ def load_lib_objects @sources = Source.order(:code) @geo_entities = GeoEntity.order(:name_en).joins(:geo_entity_type). where(:geo_entity_types => {:name => GeoEntityType::SETS[GeoEntityType::DEFAULT_SET]}) - @eu_regulations = EuRegulation.order("effective_at DESC") @eu_decision_types = EuDecisionType.opinions @ec_srgs = EcSrg.order("effective_at DESC") end From 7cbc994c830bb0c7f4506c49abb774318f0403ad Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Fri, 23 Jan 2015 22:35:58 +0000 Subject: [PATCH 55/65] sort EC SRGs by date descending --- app/controllers/admin/ec_srgs_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/admin/ec_srgs_controller.rb b/app/controllers/admin/ec_srgs_controller.rb index 9b68e6aae4..3ef8aefa47 100644 --- a/app/controllers/admin/ec_srgs_controller.rb +++ b/app/controllers/admin/ec_srgs_controller.rb @@ -7,7 +7,7 @@ class Admin::EcSrgsController < Admin::EventsController protected def collection @ec_srgs ||= end_of_association_chain. - order(:designation_id, :name).includes(:designation). + order('designation_id, effective_at DESC').includes(:designation). page(params[:page]). search(params[:query]) end From b9bddbe2b70f195c07ce0501edba5f71dbfd87ff Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Fri, 23 Jan 2015 22:36:30 +0000 Subject: [PATCH 56/65] added URL and number of linked eu_opinions to list of EC SRGs --- app/models/ec_srg.rb | 3 +++ app/views/admin/ec_srgs/_list.html.erb | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/app/models/ec_srg.rb b/app/models/ec_srg.rb index ac54215fdd..b2b342eb7e 100644 --- a/app/models/ec_srg.rb +++ b/app/models/ec_srg.rb @@ -27,6 +27,9 @@ class EcSrg < Event attr_accessible :is_current + has_many :eu_opinions, :foreign_key => :start_event_id, + :dependent => :nullify + validates :effective_at, :presence => true def self.elibrary_document_types diff --git a/app/views/admin/ec_srgs/_list.html.erb b/app/views/admin/ec_srgs/_list.html.erb index 66f9448d88..aa923370a1 100644 --- a/app/views/admin/ec_srgs/_list.html.erb +++ b/app/views/admin/ec_srgs/_list.html.erb @@ -1,6 +1,8 @@ Name Effective from + URL + No of listing changes Documents Actions @@ -16,6 +18,21 @@ <%= ec_srg.effective_at_formatted %> + + <%= link_to_unless( + ec_srg.url.blank?, + ''.html_safe, + ec_srg.url + ) { '' } %> + <%= link_to_unless( + ec_srg.multilingual_url.blank?, + ''.html_safe, + ec_srg.multilingual_url + ) { '' } %> + + + <%= ec_srg.eu_opinions.count %> + <%= link_to ec_srg.documents.count, admin_event_documents_path(ec_srg) %> From c232c72dd85fd903c180db5e1e306f264c7f41d8 Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Fri, 23 Jan 2015 22:37:53 +0000 Subject: [PATCH 57/65] use psql \COPY instead of sql COPY --- lib/tasks/helpers_for_import.rb | 6 +++++- lib/tasks/import_events.rake | 12 +++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/tasks/helpers_for_import.rb b/lib/tasks/helpers_for_import.rb index 0a3552fd81..41a412fd43 100644 --- a/lib/tasks/helpers_for_import.rb +++ b/lib/tasks/helpers_for_import.rb @@ -403,9 +403,13 @@ def drop_table(table_name) end def copy_data(path_to_file, table_name) + db_columns = db_columns_from_csv_headers(path_to_file, table_name, false) + copy_data_into_table(path_to_file, table_name, db_columns) +end + +def copy_data_into_table(path_to_file, table_name, db_columns) require 'psql_command' puts "Copying data from #{path_to_file} into tmp table #{table_name}" - db_columns = db_columns_from_csv_headers(path_to_file, table_name, false) cmd = <<-PSQL SET DateStyle = \"ISO,DMY\"; \\COPY #{table_name} (#{db_columns.join(', ')}) diff --git a/lib/tasks/import_events.rake b/lib/tasks/import_events.rake index b4f5f6e511..12027cc465 100644 --- a/lib/tasks/import_events.rake +++ b/lib/tasks/import_events.rake @@ -34,15 +34,9 @@ namespace :import do puts "There are now #{Event.count} events in the database" end - task :ec_srg, [:file] => [:environment] do |t, args| - sql = <<-PSQL - COPY events(name,effective_at,url,created_at,updated_at,type) - FROM '#{Rails.root + args.file}' - WITH DELIMITER ',' - CSV HEADER - NULL AS ' ' - PSQL - ActiveRecord::Base.connection.execute(sql) + task :ec_srg => [:environment] do + file = 'lib/files/SRG_meetings_and_SoCs_for_IT_CSV.csv' + copy_data_into_table(file, 'events', %w(name effective_at url created_at updated_at type)) puts "There are now #{EcSrg.count} EcSrg events in the database" end From 28a034c18146e05ece9a607dc2b3fc5f62dc581a Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Fri, 23 Jan 2015 22:39:17 +0000 Subject: [PATCH 58/65] task to link EU Opinions to EC SRGs --- lib/tasks/map_eu_opinions_to_ec_srgs.rake | 42 +++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 lib/tasks/map_eu_opinions_to_ec_srgs.rake diff --git a/lib/tasks/map_eu_opinions_to_ec_srgs.rake b/lib/tasks/map_eu_opinions_to_ec_srgs.rake new file mode 100644 index 0000000000..7a570d2a65 --- /dev/null +++ b/lib/tasks/map_eu_opinions_to_ec_srgs.rake @@ -0,0 +1,42 @@ +# with eu_opinions_without_ec_srg_match as ( +# select * from eu_decisions where type='EuOpinion' + +# except + +# select +# -- ec_srgs.effective_at, ec_srgs.id, +# eu_opinions.* +# from eu_decisions eu_opinions +# join events ec_srgs on ec_srgs.effective_at = eu_opinions.start_date +# where eu_opinions.type='EuOpinion' +# ) +# select +# 'http://speciesplus.net/admin/taxon_concepts/' || taxon_concept_id || '/eu_opinions/' || eu_opinions.id || '/edit' AS admin_url, +# taxon_concepts.full_name, +# geo_entities.name_en, +# eu_opinions.* +# from eu_opinions_without_ec_srg_match eu_opinions +# join taxon_concepts on taxon_concepts.id = eu_opinions.taxon_concept_id +# join geo_entities on geo_entities.id = eu_opinions.geo_entity_id +# order by start_date; + +task :map_eu_opinions_to_ec_srgs => :environment do + update_query = <<-SQL + WITH eu_opinions_matching_with_ec_srgs AS ( + SELECT + ec_srgs.effective_at, ec_srgs.id AS ec_srg_id, + eu_opinions.* + FROM eu_decisions eu_opinions + JOIN events ec_srgs ON ec_srgs.effective_at = eu_opinions.start_date + WHERE eu_opinions.type='EuOpinion' + AND eu_opinions.start_event_id != ec_srgs.id -- so that it does not re-update at next run + ) + UPDATE eu_decisions + SET start_event_id = ec_srg_id + FROM eu_opinions_matching_with_ec_srgs + WHERE eu_opinions_matching_with_ec_srgs.id = eu_decisions.id + RETURNING *; + SQL + res = ActiveRecord::Base.connection.execute update_query + puts "#{res.cmd_tuples()} rows updated" +end From 162025b7b230a7f57ff496cb037cd8668c57b54a Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Mon, 26 Jan 2015 11:46:54 +0000 Subject: [PATCH 59/65] constrain linking to EC SRG events --- lib/tasks/map_eu_opinions_to_ec_srgs.rake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tasks/map_eu_opinions_to_ec_srgs.rake b/lib/tasks/map_eu_opinions_to_ec_srgs.rake index 7a570d2a65..539d37c7ad 100644 --- a/lib/tasks/map_eu_opinions_to_ec_srgs.rake +++ b/lib/tasks/map_eu_opinions_to_ec_srgs.rake @@ -27,7 +27,7 @@ task :map_eu_opinions_to_ec_srgs => :environment do ec_srgs.effective_at, ec_srgs.id AS ec_srg_id, eu_opinions.* FROM eu_decisions eu_opinions - JOIN events ec_srgs ON ec_srgs.effective_at = eu_opinions.start_date + JOIN events ec_srgs ON ec_srgs.effective_at = eu_opinions.start_date AND ec_srgs.type = 'EcSrg' WHERE eu_opinions.type='EuOpinion' AND eu_opinions.start_event_id != ec_srgs.id -- so that it does not re-update at next run ) @@ -38,5 +38,5 @@ task :map_eu_opinions_to_ec_srgs => :environment do RETURNING *; SQL res = ActiveRecord::Base.connection.execute update_query - puts "#{res.cmd_tuples()} rows updated" + puts "#{res.cmd_tuples()} rows linked to EC SRG meetings" end From fb4a7644c3b410046a76f0145a0ea63f4346cae2 Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Mon, 26 Jan 2015 11:55:04 +0000 Subject: [PATCH 60/65] only display link to event when url is present --- .../taxon_concept/_eu_decisions.handlebars | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/species/templates/taxon_concept/_eu_decisions.handlebars b/app/assets/javascripts/species/templates/taxon_concept/_eu_decisions.handlebars index 6c89022287..78b856cd29 100644 --- a/app/assets/javascripts/species/templates/taxon_concept/_eu_decisions.handlebars +++ b/app/assets/javascripts/species/templates/taxon_concept/_eu_decisions.handlebars @@ -47,9 +47,11 @@ {{{decision.nomenclature_note_en}}} - - {{decision.start_event.name}} - + {{#if decision.start_event.url}} + + {{decision.start_event.name}} + + {{/if}} {{else}} @@ -102,9 +104,11 @@ {{{decision.nomenclature_note_en}}} - - {{decision.start_event.name}} - + {{#if decision.start_event.url}} + + {{decision.start_event.name}} + + {{/if}} {{/each}} From 29b29930a6557d6e8e74fdf7c2dd78a4a834d657 Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Mon, 26 Jan 2015 13:11:37 +0000 Subject: [PATCH 61/65] added SoC to document title --- .../species/templates/taxon_concept/_eu_decisions.handlebars | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/species/templates/taxon_concept/_eu_decisions.handlebars b/app/assets/javascripts/species/templates/taxon_concept/_eu_decisions.handlebars index 78b856cd29..4e4b1d966d 100644 --- a/app/assets/javascripts/species/templates/taxon_concept/_eu_decisions.handlebars +++ b/app/assets/javascripts/species/templates/taxon_concept/_eu_decisions.handlebars @@ -49,7 +49,7 @@ {{#if decision.start_event.url}} - {{decision.start_event.name}} + {{decision.start_event.name}} SoC {{/if}} @@ -106,7 +106,7 @@ {{#if decision.start_event.url}} - {{decision.start_event.name}} + {{decision.start_event.name}} SoC {{/if}} From 22f1c15ef23506a57373baa0c0aa3bd037bbea49 Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Mon, 26 Jan 2015 16:00:34 +0000 Subject: [PATCH 62/65] fixed updating script to match properly on nulls --- lib/tasks/map_eu_opinions_to_ec_srgs.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/map_eu_opinions_to_ec_srgs.rake b/lib/tasks/map_eu_opinions_to_ec_srgs.rake index 539d37c7ad..67595eefb6 100644 --- a/lib/tasks/map_eu_opinions_to_ec_srgs.rake +++ b/lib/tasks/map_eu_opinions_to_ec_srgs.rake @@ -29,7 +29,7 @@ task :map_eu_opinions_to_ec_srgs => :environment do FROM eu_decisions eu_opinions JOIN events ec_srgs ON ec_srgs.effective_at = eu_opinions.start_date AND ec_srgs.type = 'EcSrg' WHERE eu_opinions.type='EuOpinion' - AND eu_opinions.start_event_id != ec_srgs.id -- so that it does not re-update at next run + AND (eu_opinions.start_event_id IS NULL OR eu_opinions.start_event_id != ec_srgs.id) -- so that it does not re-update at next run ) UPDATE eu_decisions SET start_event_id = ec_srg_id From 7a4c06bdd26c93355d3800b9fd5a1f14f767e4c2 Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Mon, 26 Jan 2015 16:27:45 +0000 Subject: [PATCH 63/65] add SoC to meeting name if meeting is an EC SRG --- .../taxon_concept/_eu_decisions.handlebars | 4 +- .../20150126161813_add_soc_to_ec_srg_names.rb | 11 ++ .../api_eu_decisions_view/20150126161813.sql | 128 ++++++++++++++++++ 3 files changed, 141 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20150126161813_add_soc_to_ec_srg_names.rb create mode 100644 db/views/api_eu_decisions_view/20150126161813.sql diff --git a/app/assets/javascripts/species/templates/taxon_concept/_eu_decisions.handlebars b/app/assets/javascripts/species/templates/taxon_concept/_eu_decisions.handlebars index 4e4b1d966d..78b856cd29 100644 --- a/app/assets/javascripts/species/templates/taxon_concept/_eu_decisions.handlebars +++ b/app/assets/javascripts/species/templates/taxon_concept/_eu_decisions.handlebars @@ -49,7 +49,7 @@ {{#if decision.start_event.url}} - {{decision.start_event.name}} SoC + {{decision.start_event.name}} {{/if}} @@ -106,7 +106,7 @@ {{#if decision.start_event.url}} - {{decision.start_event.name}} SoC + {{decision.start_event.name}} {{/if}} diff --git a/db/migrate/20150126161813_add_soc_to_ec_srg_names.rb b/db/migrate/20150126161813_add_soc_to_ec_srg_names.rb new file mode 100644 index 0000000000..5b06a0d2fa --- /dev/null +++ b/db/migrate/20150126161813_add_soc_to_ec_srg_names.rb @@ -0,0 +1,11 @@ +class AddSocToEcSrgNames < ActiveRecord::Migration + def up + execute "DROP VIEW IF EXISTS api_eu_decisions_view" + execute "CREATE VIEW api_eu_decisions_view AS #{view_sql('20150126161813', 'api_eu_decisions_view')}" + end + + def down + execute "DROP VIEW IF EXISTS api_eu_decisions_view" + execute "CREATE VIEW api_eu_decisions_view AS #{view_sql('20150121232443', 'api_eu_decisions_view')}" + end +end diff --git a/db/views/api_eu_decisions_view/20150126161813.sql b/db/views/api_eu_decisions_view/20150126161813.sql new file mode 100644 index 0000000000..7d65507a26 --- /dev/null +++ b/db/views/api_eu_decisions_view/20150126161813.sql @@ -0,0 +1,128 @@ +SELECT +eu_decisions.id, +eu_decisions.type, +eu_decisions.taxon_concept_id, +ROW_TO_JSON( + ROW( + taxon_concept_id, + taxon_concepts.full_name, + taxon_concepts.author_year, + taxon_concepts.data->'rank_name' + )::api_taxon_concept +) AS taxon_concept, +eu_decisions.notes, +CASE + WHEN eu_decisions.type = 'EuOpinion' + THEN eu_decisions.start_date::DATE + WHEN eu_decisions.type = 'EuSuspension' + THEN start_event.effective_at::DATE +END AS start_date, +CASE + WHEN eu_decisions.type = 'EuOpinion' + THEN eu_decisions.is_current + WHEN eu_decisions.type = 'EuSuspension' + THEN + CASE + WHEN start_event.effective_at <= current_date AND start_event.is_current = true + AND (eu_decisions.end_event_id IS NULL OR end_event.effective_at > current_date) + THEN TRUE + ELSE + FALSE + END +END AS is_current, +eu_decisions.geo_entity_id, +ROW_TO_JSON( + ROW( + geo_entities.iso_code2, + geo_entities.name_en, + geo_entity_types.name + )::api_geo_entity +) AS geo_entity_en, +ROW_TO_JSON( + ROW( + geo_entities.iso_code2, + geo_entities.name_es, + geo_entity_types.name + )::api_geo_entity +) AS geo_entity_es, +ROW_TO_JSON( + ROW( + geo_entities.iso_code2, + geo_entities.name_fr, + geo_entity_types.name + )::api_geo_entity +) AS geo_entity_fr, +eu_decisions.start_event_id, +ROW_TO_JSON( + ROW( + start_event.name || CASE WHEN start_event.type = 'EcSrg' THEN ' Soc' ELSE '' END, + start_event.effective_at::DATE, + start_event.url + )::api_event +) AS start_event, +eu_decisions.end_event_id, +ROW_TO_JSON( + ROW( + end_event.name, + end_event.effective_at::DATE, + end_event.url + )::api_event +) AS end_event, +eu_decisions.term_id, +ROW_TO_JSON( + ROW( + terms.code, + terms.name_en + )::api_trade_code +) AS term_en, +ROW_TO_JSON( + ROW( + terms.code, + terms.name_es + )::api_trade_code +) AS term_es, +ROW_TO_JSON( + ROW( + terms.code, + terms.name_fr + )::api_trade_code +) AS term_fr, +ROW_TO_JSON( + ROW( + sources.code, + sources.name_en + )::api_trade_code +) AS source_en, +ROW_TO_JSON( + ROW( + sources.code, + sources.name_es + )::api_trade_code +) AS source_es, +ROW_TO_JSON( + ROW( + sources.code, + sources.name_fr + )::api_trade_code +) AS source_fr, +eu_decisions.source_id, +eu_decisions.eu_decision_type_id, +ROW_TO_JSON( + ROW( + eu_decision_types.name, + eu_decision_types.tooltip, + eu_decision_types.decision_type + )::api_eu_decision_type +) AS eu_decision_type, +eu_decisions.nomenclature_note_en, +eu_decisions.nomenclature_note_fr, +eu_decisions.nomenclature_note_es +FROM eu_decisions +JOIN geo_entities ON geo_entities.id = eu_decisions.geo_entity_id +JOIN geo_entity_types ON geo_entities.geo_entity_type_id = geo_entity_types.id +JOIN taxon_concepts ON taxon_concepts.id = eu_decisions.taxon_concept_id +LEFT JOIN events AS start_event ON start_event.id = eu_decisions.start_event_id +LEFT JOIN events AS end_event ON end_event.id = eu_decisions.end_event_id +LEFT JOIN trade_codes terms ON terms.id = eu_decisions.term_id AND terms.type = 'Term' +LEFT JOIN trade_codes sources ON sources.id = eu_decisions.source_id AND sources.type = 'Source' +LEFT JOIN eu_decision_types ON eu_decision_types.id = eu_decisions.eu_decision_type_id; From 2ebe6c8a26dbd31574e28a537382cd9fdec19303 Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Tue, 10 Feb 2015 11:02:30 +0000 Subject: [PATCH 64/65] prevent from raising an exception when event is missing --- app/views/admin/eu_opinions/_list.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/eu_opinions/_list.html.erb b/app/views/admin/eu_opinions/_list.html.erb index 6cdb7f2bc6..cfba72da08 100644 --- a/app/views/admin/eu_opinions/_list.html.erb +++ b/app/views/admin/eu_opinions/_list.html.erb @@ -14,7 +14,7 @@ <% collection.each do |opinion| -%> "> <%= opinion.year %> - <%= opinion.start_event.name %> + <%= opinion.start_event.try(:name) %> <%= opinion.geo_entity && opinion.geo_entity.name_en %> <%= opinion.eu_decision_type.name %> From abc00ff85b8dd398a2283ee1365a1dd788f444f1 Mon Sep 17 00:00:00 2001 From: Agnieszka Figiel Date: Tue, 10 Mar 2015 13:41:49 +0000 Subject: [PATCH 65/65] script to copy missing listing exclusions (after a bad batch copy of EU listings) --- lib/scripts/fix_eu_listing_exclusions.sql | 106 ++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 lib/scripts/fix_eu_listing_exclusions.sql diff --git a/lib/scripts/fix_eu_listing_exclusions.sql b/lib/scripts/fix_eu_listing_exclusions.sql new file mode 100644 index 0000000000..1333b42724 --- /dev/null +++ b/lib/scripts/fix_eu_listing_exclusions.sql @@ -0,0 +1,106 @@ +CREATE VIEW missing_exclusion_lcs AS +WITH parent_lcs AS ( + SELECT * FROM listing_changes + WHERE event_id = 76 +), exclusion_lcs AS ( + SELECT listing_changes.* + FROM listing_changes + JOIN parent_lcs + ON parent_lcs.id = listing_changes.parent_id +) +SELECT + exclusion_lcs.taxon_concept_id, + exclusion_lcs.species_listing_id, + exclusion_lcs.change_type_id, + copied_parents.effective_at, + copied_parents.is_current, + copied_parents.id AS parent_id, + exclusion_lcs.id As original_id, + exclusion_lcs.explicit_change, + copied_parents.created_at, + copied_parents.updated_at, + copied_parents.created_by_id, + copied_parents.updated_by_id +FROM exclusion_lcs +JOIN listing_changes copied_parents + ON copied_parents.original_id = exclusion_lcs.parent_id +LEFT JOIN listing_changes copied_exclusion_lcs + ON exclusion_lcs.id = copied_exclusion_lcs.original_id +WHERE copied_exclusion_lcs.id IS NULL; + +INSERT INTO listing_changes ( + taxon_concept_id, + species_listing_id, + change_type_id, + effective_at, + is_current, + parent_id, + original_id, + explicit_change, + created_at, + updated_at, + created_by_id, + updated_by_id +) +SELECT * FROM missing_exclusion_lcs; + + +CREATE VIEW missing_exclusion_distrs AS +WITH parent_lcs AS ( + SELECT * FROM listing_changes + WHERE event_id = 76 +), exclusion_lcs AS ( + SELECT listing_changes.* + FROM listing_changes + JOIN parent_lcs + ON parent_lcs.id = listing_changes.parent_id +), copied_exclusion_lcs AS ( + SELECT listing_changes.* + FROM listing_changes + JOIN exclusion_lcs + ON exclusion_lcs.id = listing_changes.original_id +), exclusion_distrs AS ( + SELECT listing_distributions.* + FROM listing_distributions + JOIN exclusion_lcs ON listing_distributions.listing_change_id = exclusion_lcs.id +) + SELECT + copied_exclusion_lcs.id AS listing_change_id, + exclusion_distrs.geo_entity_id, + exclusion_distrs.is_party, + exclusion_distrs.id AS original_id, + copied_exclusion_lcs.created_at, + copied_exclusion_lcs.updated_at, + copied_exclusion_lcs.created_by_id, + copied_exclusion_lcs.updated_by_id + FROM exclusion_distrs + JOIN copied_exclusion_lcs + ON copied_exclusion_lcs.original_id = exclusion_distrs.listing_change_id + LEFT JOIN listing_distributions copied_exclusion_distrs + ON exclusion_distrs.id = copied_exclusion_distrs.original_id + WHERE copied_exclusion_distrs.id IS NULL; + +INSERT INTO listing_distributions ( + listing_change_id, + geo_entity_id, + is_party, + original_id, + created_at, + updated_at, + created_by_id, + updated_by_id +) +SELECT * FROM missing_exclusion_distrs; + +DROP VIEW missing_exclusion_lcs; +DROP VIEW missing_exclusion_distrs; + + + + + + + + + +