mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-02-05 22:44:22 +08:00
SCI-3648 Error at importing one protocol without steps (#1883)
SCI-3648 Error at importing one protocol without steps
This commit is contained in:
commit
e965866d57
3 changed files with 22 additions and 38 deletions
|
@ -2,8 +2,8 @@
|
|||
|
||||
module ProtocolImporters
|
||||
class BuildProtocolFromClientService
|
||||
extend Service
|
||||
require 'protocol_importers/protocols_io/v3/errors'
|
||||
extend Service
|
||||
|
||||
attr_reader :errors, :built_protocol, :steps_assets
|
||||
|
||||
|
@ -35,15 +35,9 @@ module ProtocolImporters
|
|||
@steps_assets = pio.steps_assets unless @build_with_assets
|
||||
|
||||
self
|
||||
rescue api_errors => e
|
||||
rescue client_errors => e
|
||||
@errors[e.error_type] = e.message
|
||||
self
|
||||
rescue normalizer_errors => e
|
||||
@errors[e.error_type] = e.message
|
||||
self
|
||||
rescue StandardError => e
|
||||
@errors[:build_protocol] = e.message
|
||||
self
|
||||
end
|
||||
|
||||
def succeed?
|
||||
|
@ -99,12 +93,8 @@ module ProtocolImporters
|
|||
"ProtocolImporters::#{endpoint_name}::ProtocolNormalizer".constantize.new
|
||||
end
|
||||
|
||||
def api_errors
|
||||
def client_errors
|
||||
"ProtocolImporters::#{endpoint_name}::Error".constantize
|
||||
end
|
||||
|
||||
def normalizer_errors
|
||||
"ProtocolImporters::#{endpoint_name}::NormalizerError".constantize
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -25,15 +25,9 @@ module ProtocolImporters
|
|||
@protocols_list = normalizer.normalize_list(api_response)
|
||||
|
||||
self
|
||||
rescue api_errors => e
|
||||
rescue client_errors => e
|
||||
@errors[e.error_type] = e.message
|
||||
self
|
||||
rescue normalizer_errors => e
|
||||
@errors[e.error_type] = e.message
|
||||
self
|
||||
rescue StandardError => e
|
||||
@errors[:build_protocol] = e.message
|
||||
self
|
||||
end
|
||||
|
||||
def succeed?
|
||||
|
@ -69,12 +63,8 @@ module ProtocolImporters
|
|||
"ProtocolImporters::#{endpoint_name}::ProtocolNormalizer".constantize.new
|
||||
end
|
||||
|
||||
def api_errors
|
||||
def client_errors
|
||||
"ProtocolImporters::#{endpoint_name}::Error".constantize
|
||||
end
|
||||
|
||||
def normalizer_errors
|
||||
"ProtocolImporters::#{endpoint_name}::NormalizerError".constantize
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -44,21 +44,25 @@ module ProtocolImporters
|
|||
end
|
||||
|
||||
# set positions
|
||||
first_step_id = normalized_data[:steps].find { |s| s[:position].zero? }[:source_id]
|
||||
next_step_id = protocol_hash[:steps].find { |s| s[:previous_id] == first_step_id }.try(:[], :id)
|
||||
steps = normalized_data[:steps].map { |s| [s[:source_id], s] }.to_h
|
||||
original_order = protocol_hash[:steps].map { |m| [m[:previous_id], m[:id]] }.to_h
|
||||
current_position = 0
|
||||
while next_step_id
|
||||
if protocol_hash[:steps].any?
|
||||
first_step_id = normalized_data[:steps].find { |s| s[:position].zero? }[:source_id]
|
||||
next_step_id = protocol_hash[:steps].find { |s| s[:previous_id] == first_step_id }.try(:[], :id)
|
||||
steps = normalized_data[:steps].map { |s| [s[:source_id], s] }.to_h
|
||||
original_order = protocol_hash[:steps].map { |m| [m[:previous_id], m[:id]] }.to_h
|
||||
|
||||
current_position += 1
|
||||
steps[next_step_id][:position] = current_position
|
||||
next_step_id = original_order[next_step_id]
|
||||
end
|
||||
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 #{(step[1][:position] + 1)}" if step[1][:name].blank?
|
||||
# Check if step name are valid
|
||||
steps.each do |step|
|
||||
step[1][:name] = "Step #{(step[1][:position] + 1)}" if step[1][:name].blank?
|
||||
end
|
||||
else
|
||||
normalized_data[:steps] = []
|
||||
end
|
||||
|
||||
{ protocol: normalized_data }
|
||||
|
|
Loading…
Reference in a new issue