From 1b31319ed80693775b4f0ed70c626ff24e11d0d4 Mon Sep 17 00:00:00 2001 From: April Rieger Date: Wed, 13 Nov 2024 16:42:23 -0800 Subject: [PATCH 1/5] Updated how annotation IDs are accessed and reordering set_annotations_attributes before delete_removed_annotations to ensure new annotations are saved prior to deletion. --- app/transactions/ams/steps/create_aapb_admin_data.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/transactions/ams/steps/create_aapb_admin_data.rb b/app/transactions/ams/steps/create_aapb_admin_data.rb index 2e1dd61b..b669359e 100644 --- a/app/transactions/ams/steps/create_aapb_admin_data.rb +++ b/app/transactions/ams/steps/create_aapb_admin_data.rb @@ -43,8 +43,8 @@ def save_aapb_admin_data(change_set) set_admin_data_attributes(change_set.model.admin_data, change_set) change_set.model.admin_data.save! remove_admin_data_from_env_attributes(change_set) - delete_removed_annotations(change_set.model.admin_data, change_set) set_annotations_attributes(change_set.model.admin_data, change_set) + delete_removed_annotations(change_set.model.admin_data, change_set) remove_annotations_from_env_attributes(change_set) !!change_set.model.admin_data @@ -62,9 +62,9 @@ def set_admin_data_attributes(admin_data, change_set) def delete_removed_annotations(admin_data, change_set) return if admin_data.annotations.empty? return if change_set.annotations.blank? - ids_in_env = change_set.annotations.map(&:id) + ids_in_env = change_set.fields["annotations"].map { |a| a["id"] } admin_data.annotations.each do |annotation| - annotation.destroy unless ids_in_env.include?(annotation.id) + annotation.destroy unless ids_in_env.include?(annotation.id.to_s) end end From 00bc33b5e536cb3482ce6039f231cab22e33b2ca Mon Sep 17 00:00:00 2001 From: April Rieger Date: Fri, 15 Nov 2024 21:16:03 -0800 Subject: [PATCH 2/5] Taken from actor --- app/transactions/ams/steps/create_aapb_admin_data.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/transactions/ams/steps/create_aapb_admin_data.rb b/app/transactions/ams/steps/create_aapb_admin_data.rb index b669359e..2e1dd61b 100644 --- a/app/transactions/ams/steps/create_aapb_admin_data.rb +++ b/app/transactions/ams/steps/create_aapb_admin_data.rb @@ -43,8 +43,8 @@ def save_aapb_admin_data(change_set) set_admin_data_attributes(change_set.model.admin_data, change_set) change_set.model.admin_data.save! remove_admin_data_from_env_attributes(change_set) - set_annotations_attributes(change_set.model.admin_data, change_set) delete_removed_annotations(change_set.model.admin_data, change_set) + set_annotations_attributes(change_set.model.admin_data, change_set) remove_annotations_from_env_attributes(change_set) !!change_set.model.admin_data @@ -62,9 +62,9 @@ def set_admin_data_attributes(admin_data, change_set) def delete_removed_annotations(admin_data, change_set) return if admin_data.annotations.empty? return if change_set.annotations.blank? - ids_in_env = change_set.fields["annotations"].map { |a| a["id"] } + ids_in_env = change_set.annotations.map(&:id) admin_data.annotations.each do |annotation| - annotation.destroy unless ids_in_env.include?(annotation.id.to_s) + annotation.destroy unless ids_in_env.include?(annotation.id) end end From 5cce99c17e120bce196d85c7e5a7aa6741e91c07 Mon Sep 17 00:00:00 2001 From: April Rieger Date: Mon, 18 Nov 2024 15:59:26 -0800 Subject: [PATCH 3/5] This is the pattern from the actor stack - last commit was empty --- app/transactions/ams/steps/create_aapb_admin_data.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/transactions/ams/steps/create_aapb_admin_data.rb b/app/transactions/ams/steps/create_aapb_admin_data.rb index 2e1dd61b..6d5c2ca1 100644 --- a/app/transactions/ams/steps/create_aapb_admin_data.rb +++ b/app/transactions/ams/steps/create_aapb_admin_data.rb @@ -61,10 +61,10 @@ def set_admin_data_attributes(admin_data, change_set) def delete_removed_annotations(admin_data, change_set) return if admin_data.annotations.empty? - return if change_set.annotations.blank? - ids_in_env = change_set.annotations.map(&:id) + return if change_set.attributes["annotations"].nil? + ids_in_change_set = change_set.attributes["annotations"].select{ |ann| ann["id"].present? }.map{ |ann| ann["id"].to_i } admin_data.annotations.each do |annotation| - annotation.destroy unless ids_in_env.include?(annotation.id) + annotation.destroy unless ids_in_change_set.include?(annotation.id) end end From 4c2db80e0983b6040c49c7bcaa8a63921bc1d1a8 Mon Sep 17 00:00:00 2001 From: April Rieger Date: Mon, 18 Nov 2024 16:35:26 -0800 Subject: [PATCH 4/5] Update the .attributes to .fields for integration --- app/transactions/ams/steps/create_aapb_admin_data.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/transactions/ams/steps/create_aapb_admin_data.rb b/app/transactions/ams/steps/create_aapb_admin_data.rb index 6d5c2ca1..b1cc152b 100644 --- a/app/transactions/ams/steps/create_aapb_admin_data.rb +++ b/app/transactions/ams/steps/create_aapb_admin_data.rb @@ -42,9 +42,9 @@ def save_aapb_admin_data(change_set) find_or_create_admin_data(change_set) set_admin_data_attributes(change_set.model.admin_data, change_set) change_set.model.admin_data.save! + set_annotations_attributes(change_set.model.admin_data, change_set) remove_admin_data_from_env_attributes(change_set) delete_removed_annotations(change_set.model.admin_data, change_set) - set_annotations_attributes(change_set.model.admin_data, change_set) remove_annotations_from_env_attributes(change_set) !!change_set.model.admin_data @@ -61,8 +61,8 @@ def set_admin_data_attributes(admin_data, change_set) def delete_removed_annotations(admin_data, change_set) return if admin_data.annotations.empty? - return if change_set.attributes["annotations"].nil? - ids_in_change_set = change_set.attributes["annotations"].select{ |ann| ann["id"].present? }.map{ |ann| ann["id"].to_i } + return if change_set.fields["annotations"].nil? + ids_in_change_set = change_set.fields["annotations"].select{ |ann| ann["id"].present? }.map{ |ann| ann["id"].to_i } admin_data.annotations.each do |annotation| annotation.destroy unless ids_in_change_set.include?(annotation.id) end From 52abfd51a6b7ab8f9553565e0be0b5052177ec5e Mon Sep 17 00:00:00 2001 From: April Rieger Date: Mon, 18 Nov 2024 16:45:06 -0800 Subject: [PATCH 5/5] Test order of operations --- app/transactions/ams/steps/create_aapb_admin_data.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/transactions/ams/steps/create_aapb_admin_data.rb b/app/transactions/ams/steps/create_aapb_admin_data.rb index b1cc152b..2fb00293 100644 --- a/app/transactions/ams/steps/create_aapb_admin_data.rb +++ b/app/transactions/ams/steps/create_aapb_admin_data.rb @@ -42,9 +42,9 @@ def save_aapb_admin_data(change_set) find_or_create_admin_data(change_set) set_admin_data_attributes(change_set.model.admin_data, change_set) change_set.model.admin_data.save! - set_annotations_attributes(change_set.model.admin_data, change_set) remove_admin_data_from_env_attributes(change_set) delete_removed_annotations(change_set.model.admin_data, change_set) + set_annotations_attributes(change_set.model.admin_data, change_set) remove_annotations_from_env_attributes(change_set) !!change_set.model.admin_data