Skip to content
This repository was archived by the owner on Jun 18, 2025. It is now read-only.

Commit 51ca25f

Browse files
authored
Merge pull request #80 from emrojo/bugfix_uuids_as_data_not_supported
Quotes sample information when the data is a uuid but it does not refer
2 parents 7cd67c0 + 06446b4 commit 51ca25f

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

app/models/assets/import.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,11 @@ def annotate_container(asset, remote_asset, fact_changes)
247247
if remote_asset.try(:aliquots)
248248
remote_asset.aliquots.each do |aliquot|
249249
updates.replace_remote(asset, 'sample_tube', asset)
250-
updates.replace_remote(asset, 'sanger_sample_id', aliquot&.sample&.sanger_sample_id)
250+
updates.replace_remote(asset, 'sanger_sample_id', TokenUtil.quote_if_uuid(aliquot&.sample&.sanger_sample_id))
251251
updates.replace_remote(asset, 'sample_uuid', TokenUtil.quote(aliquot&.sample&.uuid), literal: true)
252-
updates.replace_remote(asset, 'sanger_sample_name', aliquot&.sample&.name)
253-
updates.replace_remote(asset, 'supplier_sample_name', aliquot&.sample&.sample_metadata&.supplier_name)
254-
updates.replace_remote(asset, 'sample_common_name', aliquot&.sample&.sample_metadata&.sample_common_name)
252+
updates.replace_remote(asset, 'sanger_sample_name', TokenUtil.quote_if_uuid(aliquot&.sample&.name))
253+
updates.replace_remote(asset, 'supplier_sample_name', TokenUtil.quote_if_uuid(aliquot&.sample&.sample_metadata&.supplier_name))
254+
updates.replace_remote(asset, 'sample_common_name', TokenUtil.quote_if_uuid(aliquot&.sample&.sample_metadata&.sample_common_name))
255255
end
256256
end
257257
end
@@ -265,6 +265,7 @@ def _annotate_container(asset, remote_asset, fact_changes)
265265
updates.replace_remote(asset, 'sanger_sample_id', aliquot&.sample&.sanger&.sample_id)
266266
updates.replace_remote(asset, 'sample_uuid', TokenUtil.quote(aliquot&.sample&.sanger&.sample_uuid), literal: true)
267267
updates.replace_remote(asset, 'sanger_sample_name', aliquot&.sample&.sanger&.name)
268+
268269
updates.replace_remote(asset, 'supplier_sample_name', aliquot&.sample&.supplier&.sample_name)
269270
end
270271
end

lib/token_util.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ def self.is_uuid?(str)
1919
str.kind_of?(String) && !str.match(TokenUtil.UUID_REGEXP).nil?
2020
end
2121

22+
def self.quote_if_uuid(str)
23+
return quote(str) if is_uuid?(str)
24+
return str
25+
end
26+
2227
def self.is_valid_fluidx_barcode?(barcode)
2328
barcode.to_s.starts_with?(fluidx_barcode_prefix)
2429
end

spec/lib/token_util_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@
7272
end
7373
end
7474

75+
context '#quote_if_uuid' do
76+
it 'quotes the string if is an uuid' do
77+
expect(TokenUtil.quote_if_uuid(uuid)).to eq("\"#{uuid}\"")
78+
end
79+
it 'does not quote the string if is not an uuid' do
80+
expect(TokenUtil.quote_if_uuid("text")).to eq("text")
81+
end
82+
it 'returns nil if the string is nil' do
83+
expect(TokenUtil.quote_if_uuid(nil)).to eq(nil)
84+
end
85+
end
86+
7587
context '#kind_of_asset_id?' do
7688
it 'detects when an argument is a uuid' do
7789
expect(TokenUtil.kind_of_asset_id?(uuid)).to eq(true)

0 commit comments

Comments
 (0)