class Dradis::Plugins::Projects::Upload::Template::Importer

Attributes

lookup_table[RW]
template_version[RW]

Public Instance Methods

import(params={}) click to toggle source

The import method is invoked by the framework to process a template file that has just been uploaded using the 'Import from file…' dialog.

This module will take the XMl export file created with the ProjectExport module and dump the contents into the current database.

Since we cannot ensure that the original node and category IDs as specified in the XML are free in this database, we need to keep a few lookup tables to maintain the original structure of Nodes and the Notes pointing to the right nodes and categories.

This method also returns the Node lookup table so callers can understand what changes to the original IDs have been applied. This is mainly for the benefit of the ProjectPackageUpload module that would use the translation table to re-associate the attachments in the project archive with the new node IDs in the current project.

# File lib/dradis/plugins/projects/upload/template.rb, line 31
def import(params={})

  # load the template
  logger.info { "Loading template file from: #{params[:file]}" }
  template = Nokogiri::XML(File.read(params[:file]))
  logger.info { "Done." }

  unless template.errors.empty?
    logger.error { "Invalid project template format." }
    return false
  end

  if template.xpath('/dradis-template').empty?
    error = "The uploaded file doesn't look like a Dradis project template (/dradis-template)."
    logger.fatal{ error }
    content_service.create_note text: error
    return false
  end

  # :options contains all the options we've received from the framework.
  #
  # See:
  #   Dradis::Plugins::Upload::Importer#initialize
  Rails.application.config.dradis.projects.template_uploader.new(options)
    .parse(template)
end
parse(template) click to toggle source
# File lib/dradis/plugins/projects/upload/template.rb, line 58
def parse(template)
  @template_version = template.root[:version].try(:to_i) || 1
  logger.info { "Parsing Dradis template version #{template_version.inspect}" }

  parse_categories(template)
  parse_nodes(template)
  parse_issues(template)
  parse_methodologies(template)
  parse_report_content(template)
  parse_tags(template)
  finalize(template)
  # FIXME: returning this is gross
  lookup_table
rescue Exception => e
  logger.fatal { e.message }
  logger.fatal { e.backtrace } if Rails.env.development?
  return false
end

Private Instance Methods

finalize(template) click to toggle source
# File lib/dradis/plugins/projects/upload/template.rb, line 79
def finalize(template);            raise NotImplementedError; end
parse_categories(template) click to toggle source
# File lib/dradis/plugins/projects/upload/template.rb, line 80
def parse_categories(template);    raise NotImplementedError; end
parse_issues(template) click to toggle source
# File lib/dradis/plugins/projects/upload/template.rb, line 81
def parse_issues(template);        raise NotImplementedError; end
parse_methodologies(template) click to toggle source
# File lib/dradis/plugins/projects/upload/template.rb, line 82
def parse_methodologies(template); raise NotImplementedError; end
parse_nodes(template) click to toggle source
# File lib/dradis/plugins/projects/upload/template.rb, line 83
def parse_nodes(template);         raise NotImplementedError; end
parse_report_content(template) click to toggle source
# File lib/dradis/plugins/projects/upload/template.rb, line 84
def parse_report_content(template) raise NotImplementedError; end
parse_tags(template) click to toggle source
# File lib/dradis/plugins/projects/upload/template.rb, line 85
def parse_tags(template);          raise NotImplementedError; end