-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2032 from ELIXIR-Belgium/362-add-and-edit-attribu…
…tes-in-sample-types 362 add and edit attributes in sample types
- Loading branch information
Showing
19 changed files
with
384 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
class UpdateSampleMetadataJob < TaskJob | ||
queue_with_priority 1 | ||
queue_as QueueNames::SAMPLES | ||
|
||
after_perform do |job| | ||
SampleTypeUpdateJob.perform_later(job.arguments.first, false) | ||
end | ||
|
||
def perform(sample_type, user, attribute_changes = []) | ||
@sample_type = sample_type | ||
@user = user | ||
@attribute_changes = attribute_changes | ||
|
||
Seek::Samples::SampleMetadataUpdater.new(@sample_type, @user, @attribute_changes).update_metadata | ||
end | ||
|
||
def task | ||
arguments[0].sample_metadata_update_task | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# frozen_string_literal: true | ||
|
||
module Seek | ||
module Samples | ||
|
||
class SampleMetadataUpdateException < StandardError; end | ||
|
||
# Class to handle the updating of sample metadata after updating Sample type | ||
class SampleMetadataUpdater | ||
def initialize(sample_type, user, attribute_changes) | ||
@sample_type = sample_type | ||
@user = user | ||
@attribute_change_maps = attribute_changes | ||
end | ||
|
||
def update_metadata | ||
return if @attribute_change_maps.blank? || @sample_type.blank? || @user.nil? || @sample_type.samples.blank? | ||
return unless @sample_type.locked? | ||
|
||
User.with_current_user(@user) do | ||
@sample_type.samples.in_batches(of: 1000).each do |batch| | ||
batch.each do |sample| | ||
metadata = JSON.parse(sample.json_metadata) | ||
# Update the metadata keys with the new attribute titles | ||
@attribute_change_maps.each do |change| | ||
metadata[change[:new_title]] = metadata.delete(change[:old_title]) | ||
end | ||
sample.update_column(:json_metadata, metadata.to_json) | ||
end | ||
end | ||
end | ||
end | ||
|
||
def raise_sample_metadata_update_exception | ||
raise SampleMetadataUpdateException.new('An unexpected error occurred while updating the sample metadata') | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.