Class: IevkitViews::ValidationService

Inherits:
Object
  • Object
show all
Defined in:
app/services/ievkit_views/validation_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(validation_report, action_report, q = nil) ⇒ ValidationService

Returns a new instance of ValidationService.



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

def initialize(validation_report, action_report, q = nil)
  @validations = validation_report
  @action_report = action_report
  @search = q && q['search'] ? q['search'].split(',').compact.collect(&:strip).map(&:to_s).map(&:downcase) : nil
  @filter = q && q['filter'] ? q['filter'] : { 'lines': nil, 'status': nil }
  @default_view = :files
  @reports = []
  @lines = []
  @filenames = []
  @tests = []
  @count_errors = { files: {}, lines: {} }
  do_report if @validations
end

Instance Attribute Details

#count_errorsObject (readonly)

Returns the value of attribute count_errors.



3
4
5
# File 'app/services/ievkit_views/validation_service.rb', line 3

def count_errors
  @count_errors
end

#default_viewObject

Returns the value of attribute default_view.



4
5
6
# File 'app/services/ievkit_views/validation_service.rb', line 4

def default_view
  @default_view
end

#filenamesObject (readonly)

Returns the value of attribute filenames.



3
4
5
# File 'app/services/ievkit_views/validation_service.rb', line 3

def filenames
  @filenames
end

#filterObject (readonly)

Returns the value of attribute filter.



3
4
5
# File 'app/services/ievkit_views/validation_service.rb', line 3

def filter
  @filter
end

#linesObject (readonly)

Returns the value of attribute lines.



3
4
5
# File 'app/services/ievkit_views/validation_service.rb', line 3

def lines
  @lines
end

#reportsObject (readonly)

Returns the value of attribute reports.



3
4
5
# File 'app/services/ievkit_views/validation_service.rb', line 3

def reports
  @reports
end

#searchObject (readonly)

Returns the value of attribute search.



3
4
5
# File 'app/services/ievkit_views/validation_service.rb', line 3

def search
  @search
end

#testsObject (readonly)

Returns the value of attribute tests.



3
4
5
# File 'app/services/ievkit_views/validation_service.rb', line 3

def tests
  @tests
end

Instance Method Details

#do_reportObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/services/ievkit_views/validation_service.rb', line 20

def do_report
  @validations['validation_report']['tests'].each do |test|
    report = OpenStruct.new
    report.test_id = test['test_id']
    report.error_count = test['error_count']
    report.severity = test['severity']
    report.result = test['result']
    if test['errors']
      test['errors'].each do |error|
        @report_dup = report.dup

        @report_dup.error_id = error['error_id']
        @report_dup.source_label = error['source']['label']
        @report_dup.source_objectid = error['source']['objectid']
        @report_dup.error_value = error['error_value']
        @report_dup.reference_value = error['reference_value']

        if error['target']
          error['target'].each_with_index do |target, index|
            @report_dup.send("target_#{index}_label=", target['label'])
            @report_dup.send("target_#{index}_objectid=", target['objectid'])
          end
        end

        file_infos = error['source']['file']
        parse_files(file_infos)
        line_infos = error['source']['line']
        parse_lines(line_infos)

        @report_dup.error_subtitle = I18n.t("compliance_check_results.details.#{@report_dup.test_id}")
        @report_dup.error_description = I18n.t("compliance_check_results.details.detail_#{@report_dup.error_id}", @report_dup.to_h)

        next unless parse_search?
        next unless parse_filter?(file_infos, error)

        if file_infos
          status = @action_report[:files].select{ |datas| datas['name'] == file_infos['filename'] }
          status = status.any? ? status.first['status'] : nil
          @filenames << { name: file_infos['filename'], status: status }
        end

        # TODO - Wait for IEV update
        # if line_infos
        #   status = @action_report[:lines].select{ |datas| datas['name'] == line_infos['label'] }
        #   status = status.any? ? status.first['status'] : nil
        #   @lines << { name: line_infos['label'], status: status }
        # end

        @tests << test['test_id'] if test['test_id'].present?
        @reports << @report_dup
      end
    else
      @reports << report
    end
  end
  clean_datas
end

#to_csvObject



78
79
80
81
82
83
# File 'app/services/ievkit_views/validation_service.rb', line 78

def to_csv
  CSV.generate(headers: true, col_sep: ';') do |csv|
    csv << csv_headers
    send("csv_body_#{default_view}") { |datas| csv << datas }
  end
end