Commit 140932c0dafba1342730f9bb9df4238b118db1b4
Committed by
Paulo Meireles
1 parent
3cc6ecfe
Exists in
master
and in
29 other branches
[Mezuro] Created Kalibro::ProjectResult from project_result client and entity
modified project_content to use Kalibro::ProjectResult
Showing
2 changed files
with
124 additions
and
4 deletions
Show diff stats
@@ -0,0 +1,121 @@ | @@ -0,0 +1,121 @@ | ||
1 | +class Kalibro::ProjectResult < Kalibro::Model | ||
2 | + | ||
3 | + attr_accessor :project, :date, :load_time, :analysis_time, :source_tree, :collect_time | ||
4 | + | ||
5 | + def self.last_result(project_name) | ||
6 | + last_result = request(:get_last_result_of, {:project_name => project_name})[:project_result] | ||
7 | + new last_result | ||
8 | + end | ||
9 | + | ||
10 | + def self.first_result(project_name) | ||
11 | + first_result = request(:get_first_result_of, {:project_name => project_name})[:project_result] | ||
12 | + new first_result | ||
13 | + end | ||
14 | + | ||
15 | + def self.first_result_after(project_name, date) | ||
16 | + first_result_after = request(:get_first_result_after, {:project_name => project_name, :date => date})[:project_result] | ||
17 | + new first_result_after | ||
18 | + end | ||
19 | + | ||
20 | + def self.last_result_before(project_name, date) | ||
21 | + last_result_before = request(:get_last_result_before, {:project_name => project_name, :date => date})[:project_result] | ||
22 | + new last_result_before | ||
23 | + end | ||
24 | + | ||
25 | + def self.has_results?(project_name) | ||
26 | + request(:has_results_for, {:project_name => project_name})[:has_results] | ||
27 | + end | ||
28 | + | ||
29 | + def self.has_results_before?(project_name, date) | ||
30 | + request(:has_results_before, {:project_name => project_name, :date => date})[:has_results] | ||
31 | + end | ||
32 | + | ||
33 | + def self.has_results_after?(project_name, date) | ||
34 | + request(:has_results_after, {:project_name => project_name, :date => date})[:has_results] | ||
35 | + end | ||
36 | + | ||
37 | + def project=(value) | ||
38 | + @project = (value.kind_of?(Hash)) ? Kalibro::Project.new(value) : value | ||
39 | + end | ||
40 | + | ||
41 | + def date=(value) | ||
42 | + @date = value.is_a?(String) ? DateTime.parse(value) : value | ||
43 | + end | ||
44 | + | ||
45 | + def load_time=(value) | ||
46 | + @load_time = value.to_i | ||
47 | + end | ||
48 | + | ||
49 | + def collect_time=(value) | ||
50 | + @collect_time = value.to_i | ||
51 | + end | ||
52 | + | ||
53 | + def analysis_time=(value) | ||
54 | + @analysis_time = value.to_i | ||
55 | + end | ||
56 | + | ||
57 | + #FIXME mudar a atribuição depois que refatorarmos o module_result client | ||
58 | + def source_tree=(value) | ||
59 | + @source_tree = value.kind_of?(Hash) ? Kalibro::Entities::ModuleNode.from_hash(value) : value | ||
60 | + end | ||
61 | + | ||
62 | + def formatted_load_time | ||
63 | + format_milliseconds(@load_time) | ||
64 | + end | ||
65 | + | ||
66 | + def formatted_analysis_time | ||
67 | + format_milliseconds(@analysis_time) | ||
68 | + end | ||
69 | + | ||
70 | + def format_milliseconds(value) | ||
71 | + seconds = value.to_i/1000 | ||
72 | + hours = seconds/3600 | ||
73 | + seconds -= hours * 3600 | ||
74 | + minutes = seconds/60 | ||
75 | + seconds -= minutes * 60 | ||
76 | + "#{format(hours)}:#{format(minutes)}:#{format(seconds)}" | ||
77 | + end | ||
78 | + | ||
79 | + def format(amount) | ||
80 | + ('%2d' % amount).sub(/\s/, '0') | ||
81 | + end | ||
82 | + | ||
83 | + def node_of(module_name) | ||
84 | + if module_name.nil? or module_name == project.name | ||
85 | + node = source_tree | ||
86 | + else | ||
87 | + node = get_node(module_name) | ||
88 | + end | ||
89 | + end | ||
90 | + | ||
91 | +#FIXME mudar a atribuição depois que refatorarmos o module_result client | ||
92 | + def get_node(module_name) | ||
93 | + path = Kalibro::Entities::Module.parent_names(module_name) | ||
94 | + parent = @source_tree | ||
95 | + path.each do |node_name| | ||
96 | + parent = get_leaf_from(parent, node_name) | ||
97 | + end | ||
98 | + return parent | ||
99 | + end | ||
100 | + | ||
101 | + private | ||
102 | + | ||
103 | + def self.project_result | ||
104 | + endpoint = "ProjectResult" | ||
105 | + service_address = YAML.load_file("#{RAILS_ROOT}/plugins/mezuro/service.yaml") | ||
106 | + Savon::Client.new("#{service_address}#{endpoint}Endpoint/?wsdl") | ||
107 | + end | ||
108 | + | ||
109 | + def self.request(action, request_body = nil) | ||
110 | + response = project_result.request(:kalibro, action) { soap.body = request_body } | ||
111 | + response.to_hash["#{action}_response".to_sym] | ||
112 | + end | ||
113 | + | ||
114 | + def get_leaf_from(node, module_name) | ||
115 | + node.children.each do |child_node| | ||
116 | + return child_node if child_node.module.name == module_name | ||
117 | + end | ||
118 | + nil | ||
119 | + end | ||
120 | + | ||
121 | +end |
plugins/mezuro/lib/mezuro_plugin/project_content.rb
@@ -29,7 +29,7 @@ class MezuroPlugin::ProjectContent < Article | @@ -29,7 +29,7 @@ class MezuroPlugin::ProjectContent < Article | ||
29 | 29 | ||
30 | def project_result | 30 | def project_result |
31 | begin | 31 | begin |
32 | - @project_result ||= Kalibro::Client::ProjectResultClient.last_result(name) | 32 | + @project_result ||= Kalibro::ProjectResult.last_result(name) |
33 | rescue Exception => error | 33 | rescue Exception => error |
34 | errors.add_to_base(error.message) | 34 | errors.add_to_base(error.message) |
35 | end | 35 | end |
@@ -37,9 +37,8 @@ class MezuroPlugin::ProjectContent < Article | @@ -37,9 +37,8 @@ class MezuroPlugin::ProjectContent < Article | ||
37 | 37 | ||
38 | def get_date_result(date) | 38 | def get_date_result(date) |
39 | begin | 39 | begin |
40 | - client = Kalibro::Client::ProjectResultClient.new | ||
41 | - @project_result ||= client.has_results_before(name, date) ? client.last_result_before(name, date) : | ||
42 | -client.first_result_after(name, date) | 40 | + @project_result ||= Kalibro::ProjectResult.has_results_before?(name, date) ? Kalibro::ProjectResult.last_result_before?(name, date) : |
41 | +Kalibro::ProjectResult.first_result_after(name, date) | ||
43 | rescue Exception => error | 42 | rescue Exception => error |
44 | errors.add_to_base(error.message) | 43 | errors.add_to_base(error.message) |
45 | end | 44 | end |