Class: ProformaXML::Importer

Inherits:
ServiceBase show all
Includes:
Helpers::ImportHelpers
Defined in:
lib/proformaxml/services/importer.rb

Constant Summary

Constants included from Helpers::ImportHelpers

Helpers::ImportHelpers::CONFIGURATION_NODES

Instance Method Summary collapse

Methods included from Helpers::ImportHelpers

#add_test_configuration, #attached_file_attributes, #embedded_file_attributes, #extra_configuration_from_test_configuration, #set_hash_value_if_present, #set_value, #set_value_from_xml, #shared_file_attributes, #test_files_from_test_configuration

Methods inherited from ServiceBase

call

Constructor Details

#initialize(zip:, expected_version: nil) ⇒ Importer

Returns a new instance of Importer.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/proformaxml/services/importer.rb', line 10

def initialize(zip:, expected_version: nil)
  super()
  @zip = zip
  @expected_version = expected_version

  xml = filestring_from_zip('task.xml')
  raise PreImportValidationError.new(['no task_xml found']) if xml.blank?

  @doc = Nokogiri::XML(xml, &:noblanks)
  @task = Task.new
end

Instance Method Details

#performObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/proformaxml/services/importer.rb', line 22

def perform
  version_name_extractor = VersionAndNamespaceExtractor.new doc: @doc
  @pro_ns, @doc_schema_version = version_name_extractor.perform&.values_at(:namespace, :version)

  errors = validate
  raise PreImportValidationError.new(errors.map(&:message)) if errors.any?

  @task_node = @doc.xpath("/#{@pro_ns}:task")

  set_data
  if @doc_schema_version != SCHEMA_VERSION_LATEST
    ProformaXML::TransformTask.call(task: @task, from_version: @doc_schema_version, to_version: SCHEMA_VERSION_LATEST)
  end
  @task
end