diff --git a/.service-dependencies b/.service-dependencies index a9f28156f4..a6d3ee3733 100644 --- a/.service-dependencies +++ b/.service-dependencies @@ -1,4 +1,4 @@ #syntax=v1 CONVERTER=ComPlat/chemotion-converter-app@v0.9.0 KETCHER=ptrxyz/chemotion-ketchersvc@main -SPECTRA=ComPlat/chem-spectra-app@0.11.2-patch.1 +SPECTRA=ComPlat/chem-spectra-app@0.11.3 diff --git a/app/models/concerns/attachment_jcamp_aasm.rb b/app/models/concerns/attachment_jcamp_aasm.rb index 53723b3e6a..0d517767d2 100644 --- a/app/models/concerns/attachment_jcamp_aasm.rb +++ b/app/models/concerns/attachment_jcamp_aasm.rb @@ -165,8 +165,31 @@ def generate_json_att(json_tmp, addon, to_edit = false) generate_att(json_tmp, addon, to_edit, 'json') end - def generate_csv_att(csv_tmp, addon, to_edit = false) - generate_att(csv_tmp, addon, to_edit, 'csv') + def generate_csv_att(csv_tmp, addon, to_edit = false, params={}) + csv_reader = CSV.new(csv_tmp) + csv_data = csv_reader.read + sample_id_field = csv_data[2] + sample_id_field[1] = params[:sample_id] + analysis_id_field = csv_data[3] + analysis_id_field[1] = params[:analysis_id] + dataset_id_field = csv_data[4] + dataset_id_field[1] = params[:dataset_id] + dataset_name_field = csv_data[5] + dataset_name_field[1] = params[:dataset_name] + + csv_data[2] = sample_id_field + csv_data[3] = analysis_id_field + csv_data[4] = dataset_id_field + csv_data[5] = dataset_name_field + Tempfile.create(['jcamp', '.csv']) do |new_csv_tmp| + CSV.open(new_csv_tmp, 'wb') do |csv| + csv_data.each do |row| + csv << row + end + end + new_csv_tmp.rewind + generate_att(new_csv_tmp, addon, to_edit, 'csv') + end end def generate_nmrium_att(nmrium_tmp, addon, to_edit = false) @@ -176,8 +199,17 @@ def generate_nmrium_att(nmrium_tmp, addon, to_edit = false) def build_params(params = {}) _, extname = extension_parts params[:mass] = 0.0 + params[:dataset_id] = attachable.id + params[:dataset_name] = attachable.name if attachable&.root_element.is_a?(Sample) params[:mass] = attachable&.root_element&.molecule&.exact_molecular_weight || 0.0 + params[:sample_id] = attachable&.root_element.id + + attachable.ancestors.each do |ancestor| + if ancestor.container_type == 'analysis' + params[:analysis_id] = ancestor.id + end + end end params[:ext] = extname.downcase params[:fname] = filename.to_s @@ -217,7 +249,7 @@ def create_process(is_regen) check_invalid_molfile(invalid_molfile) if spc_type == 'bagit' - read_bagit_data(arr_jcamp, arr_img, arr_csv, spc_type, is_regen) + read_bagit_data(arr_jcamp, arr_img, arr_csv, spc_type, is_regen, params) elsif arr_jcamp.length > 1 read_processed_data(arr_jcamp, arr_img, spc_type, is_regen) else @@ -251,7 +283,7 @@ def edit_process(is_regen, orig_params) unless arr_csv.nil? || arr_csv.length == 0 curr_tmp_csv = arr_csv[0] - csv_att = generate_csv_att(curr_tmp_csv, 'edit', false) + csv_att = generate_csv_att(curr_tmp_csv, 'edit', false, params) tmp_files_to_be_deleted.push(*arr_csv) delete_related_csv(csv_att) end @@ -331,7 +363,7 @@ def read_processed_data(arr_jcamp, arr_img, spc_type, is_regen) jcamp_att end - def read_bagit_data(arr_jcamp, arr_img, arr_csv, spc_type, is_regen) + def read_bagit_data(arr_jcamp, arr_img, arr_csv, spc_type, is_regen, params) jcamp_att = nil tmp_to_be_deleted = [] tmp_img_to_deleted = [] @@ -344,7 +376,7 @@ def read_bagit_data(arr_jcamp, arr_img, arr_csv, spc_type, is_regen) tmp_img_to_deleted.push(img_att) curr_tmp_csv = arr_csv[idx] - _ = generate_csv_att(curr_tmp_csv, "#{idx + 1}_bagit") + _ = generate_csv_att(curr_tmp_csv, "#{idx + 1}_bagit", false, params) tmp_to_be_deleted.push(curr_tmp_csv) jcamp_att = curr_jcamp_att if idx == 0 diff --git a/package.json b/package.json index 102a7684d7..fa90ad677b 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,8 @@ "@babel/preset-env": "^7.11.0", "@babel/preset-react": "7.10.4", "@citation-js/plugin-isbn": "0.3.0", - "@complat/chem-spectra-client": "0.11.4", - "@complat/react-spectra-editor": "0.11.4", + "@complat/chem-spectra-client": "0.11.5", + "@complat/react-spectra-editor": "0.11.5", "@novnc/novnc": "^1.2.0", "@rails/ujs": "^6.1.3-1", "@rails/webpacker": "https://github.com/rails/webpacker.git", diff --git a/spec/models/attachment_spec.rb b/spec/models/attachment_spec.rb index bdf034a27c..300ec515b3 100644 --- a/spec/models/attachment_spec.rb +++ b/spec/models/attachment_spec.rb @@ -723,9 +723,44 @@ describe '#generate_csv_att' do it 'calls #generate_att with ext = csv and all other parameters verbatim' do - expect(attachment).to receive(:generate_att).with('somethingThatGetsPassed', 'foo', false, 'csv') + csv_temp = Tempfile.new(['jcamp', '.csv']) + csv_data = Array.new(10) { + Array.new(5) {|i| i.to_s } + } + CSV.open(csv_temp, 'wb') do |csv| + csv_data.each do |row| + csv << row + end + end + + params = { + sample_id: 10, + dataset_id: 1, + dataset_name: 'root', + analysis_id: 2, + } + + expected_csv_data = Array.new(10) { |line| + Array.new(5) { |i| + if line == 2 && i == 1 + params[:sample_id].to_s + elsif line == 3 && i == 1 + params[:analysis_id].to_s + elsif line == 4 && i == 1 + params[:dataset_id].to_s + elsif line == 5 && i == 1 + params[:dataset_name].to_s + else + i.to_s + end + } + } - attachment.generate_csv_att('somethingThatGetsPassed', 'foo') + att = attachment.generate_csv_att(csv_temp, 'foo', false, params) + generated_csv = att.read_file + csv_reader = CSV.new(generated_csv) + generated_csv_data = csv_reader.read + expect(generated_csv_data).to eq expected_csv_data end end @@ -777,6 +812,8 @@ mass: 0.0, ext: 'txt', fname: 'upload.txt', + dataset_id: attachment.attachable.id, + dataset_name: attachment.attachable.name, } expect(attachment.build_params({ foo: :bar })).to eq(expected_result) diff --git a/yarn.lock b/yarn.lock index 34ba79f196..feef275d9b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1355,12 +1355,12 @@ resolved "https://registry.yarnpkg.com/@colors/colors/-/colors-1.5.0.tgz#bb504579c1cae923e6576a4f5da43d25f97bdbd9" integrity sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ== -"@complat/chem-spectra-client@0.11.4": - version "0.11.4" - resolved "https://registry.yarnpkg.com/@complat/chem-spectra-client/-/chem-spectra-client-0.11.4.tgz#651d3255bfb8a7a693bee9b15fd74b0a31b1e273" - integrity sha512-97V6Q1ztaJkUshl162kInedzusDXNDPZ3TRw40DJIMmFuCzma/bAXPEQhoIQVZzJ9ufEPzke+dl6o8RvVG7D2Q== +"@complat/chem-spectra-client@0.11.5": + version "0.11.5" + resolved "https://registry.yarnpkg.com/@complat/chem-spectra-client/-/chem-spectra-client-0.11.5.tgz#fdfa6510a34673207f91a2efe19a94735bdef178" + integrity sha512-Rrky504uYdRfxN/mdY0SQbhTCkR46bsiQhskYdzrh2jg+fIbot+aC6DyiRFM9bIwoCG4BLRwlLwFYhrwkfgdJw== dependencies: - "@complat/react-spectra-editor" "0.11.4" + "@complat/react-spectra-editor" "0.11.5" "@material-ui/core" "^3.9.4" "@material-ui/icons" "^3.0.2" axios "^0.21.1" @@ -1377,10 +1377,10 @@ redux-form "^8.3.7" redux-saga "^1.1.3" -"@complat/react-spectra-editor@0.11.4": - version "0.11.4" - resolved "https://registry.yarnpkg.com/@complat/react-spectra-editor/-/react-spectra-editor-0.11.4.tgz#5abfc4268fd2bc9a2bd954f91a0b3708843bac63" - integrity sha512-CFcDog6IriKF63FhyuG4A8kUvfncbHrQx5BphUfdUe0Ke3SOUuSZgzO5HmvB7LOMBnyTFiIu8cZAvRLNWkd2sg== +"@complat/react-spectra-editor@0.11.5": + version "0.11.5" + resolved "https://registry.yarnpkg.com/@complat/react-spectra-editor/-/react-spectra-editor-0.11.5.tgz#b2322eeda7233fddc4d1de0f34d14849f56dc80b" + integrity sha512-BNxh8XOB3wxPRNzRZx7zRXj5EFrsc0XMDjM0foTNYHPAcL8GjxCU1LSsXwfO3yBd75lhlZLYc8Qc0fUm5zXdww== dependencies: "@complat/react-svg-file-zoom-pan" "1.0.15" "@material-ui/core" "^4.10.0"