Class: IevkitViews::Report

Inherits:
Object
  • Object
show all
Includes:
ApplicationHelper
Defined in:
app/services/ievkit_views/report.rb

Direct Known Subclasses

ActionReport, ValidationReport

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ApplicationHelper

#badge_count, #get_icon, #get_icon_title

Constructor Details

#initialize(referential, link_action, type_report, link_validation = nil, search = nil) ⇒ Report

Returns a new instance of Report.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/services/ievkit_views/report.rb', line 7

def initialize(referential, link_action, type_report, link_validation = nil, search = nil)
  @datas = {}
  @result = :error
  ievkit = ::Ievkit::Job.new(referential)
  report = ievkit.get_job(link_action)
  @report = report[type_report] if report
  @validation = link_validation ? ievkit.get_job(link_validation) : nil
  if @validation && @validation['validation_report'] && @validation['validation_report']['result']
    @result = @validation['validation_report']['result'].downcase.to_sym
  end
  @search = search
end

Instance Attribute Details

#datasObject (readonly)

Returns the value of attribute datas.



5
6
7
# File 'app/services/ievkit_views/report.rb', line 5

def datas
  @datas
end

#resultObject (readonly)

Returns the value of attribute result.



5
6
7
# File 'app/services/ievkit_views/report.rb', line 5

def result
  @result
end

#searchObject (readonly)

Returns the value of attribute search.



5
6
7
# File 'app/services/ievkit_views/report.rb', line 5

def search
  @search
end

Instance Method Details

#errorsObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/services/ievkit_views/report.rb', line 69

def errors
  clean_errors = []
  return clean_errors unless @validation
  errors = @validation['validation_report']['errors']
  return clean_errors unless errors
  errors.each do |error|
    error = key_to_sym(error)
    error[:source_label] = error[:source][:label]
    error[:source_objectid] = error[:source][:objectid]
    error[:filename] = error[:source][:file][:filename] if error[:source][:file]
    if error[:target]
      error[:target].each_with_index do |target, index|
        target = key_to_sym(target)
        error[:target][index] = target
        error[:"target_#{index}_label"] = target[:label]
        error[:"target_#{index}_objectid"] = target[:objectid]
      end
    end
    error[:test_name] = I18n.t("compliance_check_results.details.#{error[:test_id]}")
    begin
      error[:error_name] = I18n.t("compliance_check_results.details.detail_#{error[:error_id]}", error)
    rescue => e
      Ievkit::Log.logger.error e.message
      error[:error_name] = e.message
    end
    clean_errors << error
  end
  clean_errors
end

#search_for(datas) ⇒ Object



33
34
35
36
37
38
# File 'app/services/ievkit_views/report.rb', line 33

def search_for(datas)
  return datas unless search.present? && datas.present?
  files = []
  files << datas.select{ |value| value.to_s.downcase =~/#{search.downcase}/i }
  files.flatten!
end

#sort_datas(datas) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/services/ievkit_views/report.rb', line 20

def sort_datas(datas)
  sorted_by = { error: [], warning: [], ok: [], ignored: [], '': [] }
  datas.flatten.each{ |d|
    sorted_by[d[:status]] << d
  }
  sorted_by.each{ |key, value|
    sorted_by[key] = value.sort_by{ |a| [a[:count_error], a[:count_warning]] }.reverse
  }
  [].tap{ |a|
    a << sorted_by.map{ |_k, v| v }
  }.flatten!
end

#sum_report(datas) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/services/ievkit_views/report.rb', line 40

def sum_report(datas)
  return {} unless datas.present?
  {}.tap{ |hash|
    datas.map{ |el| el[:type] }.uniq.each do |type|
      hash[type] = {
        ok: badge_count(datas, type, :ok),
        error: badge_count(datas, type, :error, :warning),
        ignored: badge_count(datas, type, :ignored)
      }
    end
  }
end

#sum_report_for_tests(datas) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/services/ievkit_views/report.rb', line 53

def sum_report_for_tests(datas)
  return {} unless datas.present?
  {}.tap{ |hash|
    hash['tests-1-2-error'] = { ok: 0, error: 0, ignored: 0 }
    hash['tests-1-2-warning'] = { ok: 0, error: 0, ignored: 0 }
    hash['tests-3-4-error'] = { ok: 0, error: 0, ignored: 0 }
    hash['tests-3-4-warning'] = { ok: 0, error: 0, ignored: 0 }
    datas.each do |d|
      severity = d[:severity] == :error ? :error : :warning
      status = d[:status] == :warning ? :error : d[:status]
      hash["tests-1-2-#{severity}"][status] += 1 if %w(1 2).include? d[:name][0]
      hash["tests-3-4-#{severity}"][status] += 1 if %w(3 4).include? d[:name][0]
    end
  }
end