avmtrf1-tools 0.27.0 → 0.31.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -0
  3. data/lib/avmtrf1/esosti/entities/issue.rb +5 -31
  4. data/lib/avmtrf1/esosti/instance.rb +4 -0
  5. data/lib/avmtrf1/esosti/instance/changed.rb +33 -0
  6. data/lib/avmtrf1/esosti/raw_data_sanitizer.rb +47 -0
  7. data/lib/avmtrf1/inventario_sistemas.rb +40 -0
  8. data/lib/avmtrf1/inventario_sistemas/parser.rb +42 -0
  9. data/lib/avmtrf1/inventario_sistemas/parser/body.rb +27 -0
  10. data/lib/avmtrf1/inventario_sistemas/parser/body_row.rb +12 -0
  11. data/lib/avmtrf1/inventario_sistemas/parser/header.rb +38 -0
  12. data/lib/avmtrf1/inventario_sistemas/parser/header_column.rb +27 -0
  13. data/lib/avmtrf1/inventario_sistemas/site_build.rb +71 -0
  14. data/lib/avmtrf1/inventario_sistemas/site_build/html_page_base.rb +41 -0
  15. data/lib/avmtrf1/inventario_sistemas/site_build/html_page_base/elements.rb +54 -0
  16. data/lib/avmtrf1/inventario_sistemas/site_build/html_page_base/layout.rb +55 -0
  17. data/lib/avmtrf1/inventario_sistemas/site_build/html_page_base/stylesheet.css +57 -0
  18. data/lib/avmtrf1/inventario_sistemas/site_build/index.rb +20 -0
  19. data/lib/avmtrf1/inventario_sistemas/site_build/sistema.rb +62 -0
  20. data/lib/avmtrf1/inventario_sistemas/site_build/sistemas_index.rb +31 -0
  21. data/lib/avmtrf1/oracle/connection/base.rb +1 -0
  22. data/lib/avmtrf1/oracle/oci8.rb +8 -4
  23. data/lib/avmtrf1/patches/eac_launcher/git/base.rb +0 -15
  24. data/lib/avmtrf1/redmine/instance.rb +2 -1
  25. data/lib/avmtrf1/rest_provider/instance.rb +13 -53
  26. data/lib/avmtrf1/rest_provider/instance/issues.rb +30 -0
  27. data/lib/avmtrf1/rest_provider/request.rb +44 -0
  28. data/lib/avmtrf1/rest_provider/response.rb +77 -0
  29. data/lib/avmtrf1/ruby.rb +9 -0
  30. data/lib/avmtrf1/ruby/gems.rb +11 -0
  31. data/lib/avmtrf1/ruby/gems/dependency.rb +20 -0
  32. data/lib/avmtrf1/ruby/gems/not_found_error.rb +17 -0
  33. data/lib/avmtrf1/tools/runner.rb +12 -0
  34. data/lib/avmtrf1/tools/runner/esosti.rb +2 -21
  35. data/lib/avmtrf1/tools/runner/esosti/changed.rb +52 -0
  36. data/lib/avmtrf1/tools/runner/esosti/fetch.rb +52 -0
  37. data/lib/avmtrf1/tools/runner/esosti/request.rb +88 -0
  38. data/lib/avmtrf1/tools/runner/inventario_sistemas.rb +73 -0
  39. data/lib/avmtrf1/tools/version.rb +1 -1
  40. metadata +64 -40
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'addressable'
4
+
5
+ module Avmtrf1
6
+ class InventarioSistemas
7
+ class SiteBuild
8
+ class HtmlPageBase
9
+ module Elements
10
+ def html_link(link_text, link_href)
11
+ "<a href=#{link_href}>#{link_text}</a>"
12
+ end
13
+
14
+ def html_linkfy(input)
15
+ output = url_or_text(input)
16
+ if output.is_a?(::Addressable::URI)
17
+ html_link(output, output)
18
+ else
19
+ output
20
+ end
21
+ end
22
+
23
+ def html_table(columns, rows)
24
+ b = '<table><theader>'
25
+ b += html_table_row(columns, 'th', '')
26
+ b += '</theader><tbody>'
27
+ rows.each_with_index do |row, index|
28
+ b += html_table_row(row, 'td', (index % 2).zero? ? 'even' : 'odd')
29
+ end
30
+ b + '</tbody></theader>'
31
+ end
32
+
33
+ def html_table_row(values, tag, css_class)
34
+ begin_tag = "<#{tag} class='#{css_class}'>"
35
+ end_tag = "</#{tag}>"
36
+ '<tr>' + values.map { |v| begin_tag + v + end_tag }.join + "</tr>\n"
37
+ end
38
+
39
+ def self_html_link
40
+ html_link(title, href)
41
+ end
42
+
43
+ def url_or_text(input)
44
+ converted_input = input.gsub('\\', '/').gsub(%r{\A//}, 'smb://')
45
+ uri = ::Addressable::URI.parse(converted_input)
46
+ uri.scheme.present? && uri.host.present? ? uri : input
47
+ rescue Addressable::URI::InvalidURIError
48
+ input
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avmtrf1
4
+ class InventarioSistemas
5
+ class SiteBuild
6
+ class HtmlPageBase
7
+ module Layout
8
+ def metadata_info
9
+ "<div class='input_metadata'>" \
10
+ "Extraído de <strong>#{site.input_file.basename}</strong>." \
11
+ '</div>'
12
+ end
13
+
14
+ def output_body
15
+ <<HTML
16
+ <body><div id="top">
17
+ #{output_navbar}
18
+ <h1>#{site_title}</h1>
19
+ #{metadata_info}
20
+ </div><div id="inner">
21
+ <h2>#{title}</h2>
22
+ #{output_inner_content}
23
+ </div></body>
24
+ HTML
25
+ end
26
+
27
+ def output_content
28
+ "<html>\n" + output_header + output_body + '</html>'
29
+ end
30
+
31
+ def output_header
32
+ <<HTML
33
+ <head>
34
+ <meta charset="UTF-8">
35
+ <title>#{site_title} - #{title}</title>
36
+ <style>
37
+ #{::File.read(::File.join(__dir__, 'stylesheet.css'))}
38
+ </style>
39
+ </head>
40
+ HTML
41
+ end
42
+
43
+ def output_navbar
44
+ '<nav>' + output_navbar_path(false) + '</nav>'
45
+ end
46
+
47
+ def output_navbar_path(links)
48
+ (parent.present? ? parent.output_navbar_path(true) + NAVBAR_SEPARATOR : '') +
49
+ (links ? self_html_link : title)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,57 @@
1
+ body, #top, #top * {
2
+ padding: 0;
3
+ margin: 0;
4
+ box-sizing: border-box;
5
+ }
6
+
7
+ #top * {
8
+ padding: 0.3em;
9
+ }
10
+
11
+ #inner {
12
+ margin: 0.3em;
13
+ }
14
+
15
+ nav {
16
+ padding: 0.2em;
17
+ }
18
+
19
+ a {
20
+ color: blue;
21
+ }
22
+
23
+ a:visited {
24
+ color: darkblue;
25
+ }
26
+
27
+ h1 {
28
+ text-align: right;
29
+ background-color: lightyellow;
30
+ }
31
+
32
+ .input_metadata {
33
+ text-align: right;
34
+ background-color: lightblue;
35
+ }
36
+
37
+ table {
38
+ border: thin solid black;
39
+ border-collapse: collapse;
40
+ }
41
+
42
+ .odd {
43
+ background-color: lightgray;
44
+ }
45
+
46
+ td, th {
47
+ border-left: thin solid black;
48
+ }
49
+
50
+ th {
51
+ border-bottom: thin solid black;
52
+ }
53
+
54
+ nav, nav a, nav a:visited, th {
55
+ background-color: black;
56
+ color: white;
57
+ }
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'avmtrf1/inventario_sistemas/site_build/html_page_base'
5
+
6
+ module Avmtrf1
7
+ class InventarioSistemas
8
+ class SiteBuild
9
+ class Index < ::Avmtrf1::InventarioSistemas::SiteBuild::HtmlPageBase
10
+ def output_inner_content
11
+ ['<ul>', "<li>#{site.sistemas_index.self_html_link}</li>", '</ul>'].join("\n")
12
+ end
13
+
14
+ def title
15
+ 'Índice'
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'avmtrf1/inventario_sistemas/parser/header_column'
5
+ require 'avmtrf1/inventario_sistemas/site_build/html_page_base'
6
+
7
+ module Avmtrf1
8
+ class InventarioSistemas
9
+ class SiteBuild
10
+ class Sistema < ::Avmtrf1::InventarioSistemas::SiteBuild::HtmlPageBase
11
+ attr_reader :raw_row
12
+
13
+ def initialize(site, parent, raw_row)
14
+ super(site, parent)
15
+ @raw_row = raw_row
16
+ end
17
+
18
+ def id
19
+ nome.parameterize
20
+ end
21
+
22
+ def gestor
23
+ column_value('gestor na jf1', 'unidade')
24
+ end
25
+
26
+ def nome
27
+ column_value('sistema', 'sigla')
28
+ end
29
+
30
+ def producao
31
+ html_linkfy(column_value('ambientes', 'produção – serv. ap'))
32
+ end
33
+
34
+ def responsavel
35
+ %w[unidade seção nome]
36
+ .map { |sub| column_value('responsável pelo desenvolvimento', sub) }
37
+ .reject(&:blank?).join(' » ')
38
+ end
39
+
40
+ def output_inner_content
41
+ column_values = site.parser.header_columns.map { |c| [c.key, column_value(c)] }
42
+ '<h3>Detalhes</h3>' + html_table(%w[Campo Valor], column_values)
43
+ end
44
+
45
+ def title
46
+ nome
47
+ end
48
+
49
+ def column_value(main, sub = nil)
50
+ column = if main.is_a?(::Avmtrf1::InventarioSistemas::Parser::HeaderColumn)
51
+ main
52
+ else
53
+ site.column(main, sub)
54
+ end
55
+ raise 'Out of bound' if column.index >= raw_row.count
56
+
57
+ raw_row[column.index]
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'avmtrf1/inventario_sistemas/site_build/html_page_base'
5
+
6
+ module Avmtrf1
7
+ class InventarioSistemas
8
+ class SiteBuild
9
+ class SistemasIndex < ::Avmtrf1::InventarioSistemas::SiteBuild::HtmlPageBase
10
+ def output_inner_content
11
+ output_count + output_list
12
+ end
13
+
14
+ def title
15
+ 'Sistemas'
16
+ end
17
+
18
+ def output_count
19
+ "<p>Quantidade: #{site.sistemas.count}</p>"
20
+ end
21
+
22
+ def output_list
23
+ html_table(
24
+ %w[Nome Produção Responsável Gestor],
25
+ site.sistemas.map { |s| [s.self_html_link, s.producao, s.responsavel, s.gestor] }
26
+ )
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -12,6 +12,7 @@ module Avmtrf1
12
12
  delegate :exec, to: :connection
13
13
 
14
14
  def initialize(connection_string)
15
+ ::Avmtrf1::Oracle::Oci8.require_lib
15
16
  @connection = OCI8.new(connection_string)
16
17
  end
17
18
 
@@ -1,15 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'avmtrf1/ruby/gems/dependency'
4
+
3
5
  module Avmtrf1
4
6
  module Oracle
5
7
  module Oci8
6
- NLS_LANG_DEFAULT_VALUE = 'BRAZILIAN PORTUGUESE_BRAZIL.WE8ISO8859P1'
8
+ NLS_LANG_DEFAULT_VALUE = 'BRAZILIAN PORTUGUESE_BRAZIL.UTF8'
7
9
  NLS_LANG_ENVIRONMENT_KEY = 'NLS_LANG'
8
10
 
9
11
  class << self
12
+ def dependency
13
+ @dependency ||= ::Avmtrf1::Ruby::Gems::Dependency.new('ruby-oci8', 'oci8')
14
+ end
15
+
10
16
  def require_lib
11
17
  nls_lang_set
12
- require 'oci8'
18
+ dependency.require_lib
13
19
  end
14
20
 
15
21
  def nls_lang_set
@@ -21,5 +27,3 @@ module Avmtrf1
21
27
  end
22
28
  end
23
29
  end
24
-
25
- ::Avmtrf1::Oracle::Oci8.require_lib
@@ -16,21 +16,6 @@ module Avmtrf1
16
16
  end
17
17
 
18
18
  module InstanceMethods
19
- def execute(*args)
20
- args, options = build_args(args)
21
- ::EacRubyUtils::Envs.local.command(*args).execute(options)
22
- end
23
-
24
- def system(*args)
25
- args, options = build_args(args)
26
- ::EacRubyUtils::Envs.local.command(*args).system(options)
27
- end
28
-
29
- def command(*args)
30
- args, _options = build_args(args)
31
- ::EacRubyUtils::Envs.local.command(*args)
32
- end
33
-
34
19
  def status_files
35
20
  execute!('-c', 'core.quotepath=off', 'status', '--porcelain').each_line.map do |line|
36
21
  parse_status_file(line)
@@ -31,7 +31,8 @@ module Avmtrf1
31
31
  private
32
32
 
33
33
  def issue_statuses
34
- request('/issue_statuses').fetch('issue_statuses').map do |data|
34
+ request_json('/issue_statuses').response.body_data_or_raise.fetch('issue_statuses')
35
+ .map do |data|
35
36
  ::Avmtrf1::Redmine::Entities::IssueStatus.new(self, data)
36
37
  end
37
38
  end
@@ -1,9 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'avmtrf1/rest_provider/request'
3
4
  require 'curb'
4
- require 'json'
5
- require 'avmtrf1/jira/entities/issue'
6
- require 'eac_ruby_utils/console/speaker'
5
+ require 'eac_ruby_utils/core_ext'
7
6
 
8
7
  module Avmtrf1
9
8
  module RestProvider
@@ -12,58 +11,19 @@ module Avmtrf1
12
11
  # * self.build_service_url(service_url_suffix)
13
12
  # * self.issue_get_url_suffix(provider_issue_id)
14
13
  class Instance
15
- include ::EacRubyUtils::Console::Speaker
16
-
17
- attr_reader :root_url, :username, :password
18
-
19
- def initialize(root_url, username, password)
20
- @root_url = root_url
21
- @username = username
22
- @password = password
23
- end
24
-
25
- def find_issue(global_issue_id)
26
- parsed = self.class.parse_issue_id(global_issue_id)
27
- parsed.present? ? issue(parsed.provider_issue_id) : nil
28
- end
29
-
30
- def issue(provider_issue_id)
31
- issue_class.new(self, request(issue_get_url_suffix(provider_issue_id)))
32
- end
33
-
34
- def request(service_url_suffix)
35
- url = build_service_url(service_url_suffix)
36
- infov 'URL', url
37
- c = ::Curl::Easy.new(url)
38
- c.http_auth_types = :basic
39
- c.username = username
40
- c.password = password
41
- c.headers['Accept'] = 'application/json'
42
- curl_perform(c)
43
- end
44
-
45
- def issue_class
46
- "#{self.class.name.deconstantize}::Entities::Issue".constantize
47
- end
48
-
49
- private
50
-
51
- def curl_perform(curl)
52
- raise 'Curl failed' unless curl.perform
53
-
54
- infov 'Return status', curl.status
55
- return JSON.parse(curl.body_str) if curl.status.to_i == 200
56
-
57
- raise curl_raise_message(curl)
14
+ require_sub __FILE__, include_modules: true
15
+ common_constructor :root_url, :username, :password
16
+
17
+ def request(service_url_suffix, headers = {}, &body_data_proc)
18
+ r = Avmtrf1::RestProvider::Request.new(build_service_url(service_url_suffix),
19
+ body_data_proc)
20
+ headers.each { |name, value| r.header(name, value) }
21
+ r.autenticate(username, password)
22
+ r
58
23
  end
59
24
 
60
- def curl_raise_message(curl)
61
- raise <<~MESSAGE
62
- "#{curl.url} returned #{curl.status.to_i}:
63
- #{'=' * 10}
64
- #{curl.body_str}
65
- #{'=' * 10}"
66
- MESSAGE
25
+ def request_json(service_url_suffix, headers = {}, &body_data_proc)
26
+ request(service_url_suffix, headers.merge('Accept' => 'application/json'), &body_data_proc)
67
27
  end
68
28
  end
69
29
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avmtrf1
4
+ module RestProvider
5
+ class Instance
6
+ module Issues
7
+ def find_issue(global_issue_id)
8
+ parsed = self.class.parse_issue_id(global_issue_id)
9
+ parsed.present? ? issue(parsed.provider_issue_id) : nil
10
+ end
11
+
12
+ def issue(provider_issue_id)
13
+ issue_request(provider_issue_id).response.body_data_or_raise
14
+ end
15
+
16
+ # @return [Avmtrf1::RestProvider::Request]
17
+ def issue_request(provider_issue_id)
18
+ request_json(issue_get_url_suffix(provider_issue_id)) do |data|
19
+ data = issue_class.parse_data(data) if issue_class.respond_to?(:parse_data)
20
+ data.present? ? issue_class.new(self, data) : nil
21
+ end
22
+ end
23
+
24
+ def issue_class
25
+ "#{self.class.name.deconstantize}::Entities::Issue".constantize
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end