From 8146a6a42c9ad0ecc38fabf4acc30291607ee4bd Mon Sep 17 00:00:00 2001 From: Jure Grabnar Date: Fri, 28 Jun 2019 11:29:03 +0200 Subject: [PATCH] Assign name = position if protocolsIO step has no name --- .../protocols_io/v3/protocol_normalizer.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/utilities/protocol_importers/protocols_io/v3/protocol_normalizer.rb b/app/utilities/protocol_importers/protocols_io/v3/protocol_normalizer.rb index dd43beee2..073ac3255 100644 --- a/app/utilities/protocol_importers/protocols_io/v3/protocol_normalizer.rb +++ b/app/utilities/protocol_importers/protocols_io/v3/protocol_normalizer.rb @@ -50,11 +50,17 @@ module ProtocolImporters original_order = protocol_hash[:steps].map { |m| [m[:previous_id], m[:id]] }.to_h current_position = 0 while next_step_id + current_position += 1 steps[next_step_id][:position] = current_position next_step_id = original_order[next_step_id] end + # Check if step name are valid + steps.each do |step| + step[1][:name] = (step[1][:position] + 1).to_s if step[1][:name].blank? + end + { protocol: normalized_data } rescue StandardError => e raise ProtocolImporters::ProtocolsIO::V3::NormalizerError.new(e.class.to_s.downcase.to_sym), e.message