kalibro_gatekeeper_client 0.0.1.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +29 -0
  6. data/AUTHORS +4 -0
  7. data/COPYING +674 -0
  8. data/COPYING.LESSER +165 -0
  9. data/Gemfile +4 -0
  10. data/README.md +77 -0
  11. data/Rakefile +6 -0
  12. data/cucumber.yml +1 -0
  13. data/features/base_tool/all_names.feature +8 -0
  14. data/features/base_tool/find_by_name.feature +12 -0
  15. data/features/configuration/all.feature +10 -0
  16. data/features/metric_configuration/find.feature +18 -0
  17. data/features/metric_configuration/metric_configurations_of.feature +18 -0
  18. data/features/metric_result/descendant_results.feature +19 -0
  19. data/features/metric_result/history_of.feature +20 -0
  20. data/features/metric_result/metric_results_of.feature +19 -0
  21. data/features/module_result/children.feature +18 -0
  22. data/features/module_result/find.feature +15 -0
  23. data/features/module_result/history_of.feature +11 -0
  24. data/features/processing/first_processing_after.feature +18 -0
  25. data/features/processing/first_processing_of.feature +18 -0
  26. data/features/processing/has_processing.feature +18 -0
  27. data/features/processing/has_processing_after.feature +18 -0
  28. data/features/processing/has_processing_before.feature +18 -0
  29. data/features/processing/has_ready_processing.feature +18 -0
  30. data/features/processing/last_processing_before.feature +18 -0
  31. data/features/processing/last_processing_of.feature +18 -0
  32. data/features/processing/last_processing_state_of.feature +18 -0
  33. data/features/processing/last_ready_processing_of.feature +18 -0
  34. data/features/processing/processing_of.feature +32 -0
  35. data/features/processing/processing_with_date_of.feature +32 -0
  36. data/features/project/all.feature +10 -0
  37. data/features/project/creation.feature +9 -0
  38. data/features/project/destroy.feature +10 -0
  39. data/features/project/exists.feature +9 -0
  40. data/features/project/find.feature +10 -0
  41. data/features/range/all.feature +14 -0
  42. data/features/range/exists.feature +13 -0
  43. data/features/range/find.feature +14 -0
  44. data/features/range/ranges_of.feature +22 -0
  45. data/features/range/save.feature +14 -0
  46. data/features/reading/all.feature +13 -0
  47. data/features/reading/exists.feature +13 -0
  48. data/features/reading/find.feature +11 -0
  49. data/features/reading/readings_of.feature +11 -0
  50. data/features/reading_group/all.feature +10 -0
  51. data/features/repository/all.feature +14 -0
  52. data/features/repository/cancel_processing.feature +14 -0
  53. data/features/repository/exists.feature +14 -0
  54. data/features/repository/find.feature +14 -0
  55. data/features/repository/of.feature +15 -0
  56. data/features/repository/process.feature +16 -0
  57. data/features/repository/types.feature +9 -0
  58. data/features/step_definitions/base_tool_steps.rb +28 -0
  59. data/features/step_definitions/configuration_steps.rb +11 -0
  60. data/features/step_definitions/metric_configuration_steps.rb +52 -0
  61. data/features/step_definitions/metric_result_steps.rb +29 -0
  62. data/features/step_definitions/metric_steps.rb +3 -0
  63. data/features/step_definitions/module_result_steps.rb +30 -0
  64. data/features/step_definitions/processing_steps.rb +91 -0
  65. data/features/step_definitions/project_steps.rb +48 -0
  66. data/features/step_definitions/range_steps.rb +68 -0
  67. data/features/step_definitions/reading_group_steps.rb +19 -0
  68. data/features/step_definitions/reading_steps.rb +39 -0
  69. data/features/step_definitions/repository_steps.rb +61 -0
  70. data/features/support/env.rb +25 -0
  71. data/features/support/kalibro_cucumber_helpers.yml.sample +10 -0
  72. data/kalibro_gatekeeper_client.gemspec +49 -0
  73. data/lib/kalibro_gatekeeper_client/entities/base_tool.rb +55 -0
  74. data/lib/kalibro_gatekeeper_client/entities/configuration.rb +34 -0
  75. data/lib/kalibro_gatekeeper_client/entities/date_metric_result.rb +39 -0
  76. data/lib/kalibro_gatekeeper_client/entities/date_module_result.rb +39 -0
  77. data/lib/kalibro_gatekeeper_client/entities/metric.rb +21 -0
  78. data/lib/kalibro_gatekeeper_client/entities/metric_configuration.rb +76 -0
  79. data/lib/kalibro_gatekeeper_client/entities/metric_configuration_snapshot.rb +57 -0
  80. data/lib/kalibro_gatekeeper_client/entities/metric_result.rb +72 -0
  81. data/lib/kalibro_gatekeeper_client/entities/model.rb +174 -0
  82. data/lib/kalibro_gatekeeper_client/entities/module.rb +27 -0
  83. data/lib/kalibro_gatekeeper_client/entities/module_result.rb +75 -0
  84. data/lib/kalibro_gatekeeper_client/entities/process_time.rb +31 -0
  85. data/lib/kalibro_gatekeeper_client/entities/processing.rb +113 -0
  86. data/lib/kalibro_gatekeeper_client/entities/project.rb +35 -0
  87. data/lib/kalibro_gatekeeper_client/entities/range.rb +100 -0
  88. data/lib/kalibro_gatekeeper_client/entities/range_snapshot.rb +37 -0
  89. data/lib/kalibro_gatekeeper_client/entities/reading.rb +67 -0
  90. data/lib/kalibro_gatekeeper_client/entities/reading_group.rb +44 -0
  91. data/lib/kalibro_gatekeeper_client/entities/repository.rb +89 -0
  92. data/lib/kalibro_gatekeeper_client/entities/repository_observer.rb +50 -0
  93. data/lib/kalibro_gatekeeper_client/entities/stack_trace_element.rb +31 -0
  94. data/lib/kalibro_gatekeeper_client/entities/throwable.rb +42 -0
  95. data/lib/kalibro_gatekeeper_client/entities.rb +37 -0
  96. data/lib/kalibro_gatekeeper_client/errors/record_not_found.rb +22 -0
  97. data/lib/kalibro_gatekeeper_client/errors/standard.rb +24 -0
  98. data/lib/kalibro_gatekeeper_client/errors.rb +18 -0
  99. data/lib/kalibro_gatekeeper_client/helpers/aggregation_options.rb +25 -0
  100. data/lib/kalibro_gatekeeper_client/helpers/hash_converters.rb +48 -0
  101. data/lib/kalibro_gatekeeper_client/helpers/request_methods.rb +47 -0
  102. data/lib/kalibro_gatekeeper_client/helpers/xml_converters.rb +20 -0
  103. data/lib/kalibro_gatekeeper_client/kalibro_cucumber_helpers/configuration.rb +39 -0
  104. data/lib/kalibro_gatekeeper_client/kalibro_cucumber_helpers/hooks.rb +56 -0
  105. data/lib/kalibro_gatekeeper_client/kalibro_cucumber_helpers/scripts/delete_all_kalibro_entries.sh +23 -0
  106. data/lib/kalibro_gatekeeper_client/kalibro_cucumber_helpers/scripts/prepare_kalibro_query_file.sh +38 -0
  107. data/lib/kalibro_gatekeeper_client/kalibro_cucumber_helpers/scripts/put_kalibro_on_test_mode.sh +39 -0
  108. data/lib/kalibro_gatekeeper_client/kalibro_cucumber_helpers/scripts/return_kalibro_from_test_mode.sh +26 -0
  109. data/lib/kalibro_gatekeeper_client/kalibro_cucumber_helpers.rb +40 -0
  110. data/lib/kalibro_gatekeeper_client/version.rb +19 -0
  111. data/lib/kalibro_gatekeeper_client.rb +61 -0
  112. data/lib/rake/test_task.rb +57 -0
  113. data/spec/entities/base_tool_spec.rb +168 -0
  114. data/spec/entities/configuration_spec.rb +61 -0
  115. data/spec/entities/date_metric_result_spec.rb +62 -0
  116. data/spec/entities/date_module_result_spec.rb +61 -0
  117. data/spec/entities/metric_configuration_snapshot_spec.rb +107 -0
  118. data/spec/entities/metric_configuration_spec.rb +173 -0
  119. data/spec/entities/metric_result_spec.rb +188 -0
  120. data/spec/entities/metric_spec.rb +47 -0
  121. data/spec/entities/model_spec.rb +322 -0
  122. data/spec/entities/module_result_spec.rb +163 -0
  123. data/spec/entities/process_time_spec.rb +33 -0
  124. data/spec/entities/processing_spec.rb +334 -0
  125. data/spec/entities/project_spec.rb +68 -0
  126. data/spec/entities/range_snapshot_spec.rb +50 -0
  127. data/spec/entities/range_spec.rb +225 -0
  128. data/spec/entities/reading_group_spec.rb +90 -0
  129. data/spec/entities/reading_spec.rb +148 -0
  130. data/spec/entities/repository_observer_spec.rb +123 -0
  131. data/spec/entities/repository_spec.rb +191 -0
  132. data/spec/entities/stack_trace_element_spec.rb +26 -0
  133. data/spec/entities/throwable_spec.rb +51 -0
  134. data/spec/factories/base_tools.rb +31 -0
  135. data/spec/factories/configurations.rb +29 -0
  136. data/spec/factories/date_metric_results.rb +28 -0
  137. data/spec/factories/date_module_results.rb +22 -0
  138. data/spec/factories/metric_configurations.rb +28 -0
  139. data/spec/factories/metric_configurations_snapshot.rb +26 -0
  140. data/spec/factories/metric_results.rb +24 -0
  141. data/spec/factories/metrics.rb +35 -0
  142. data/spec/factories/models.rb +20 -0
  143. data/spec/factories/module_results.rb +33 -0
  144. data/spec/factories/modules.rb +22 -0
  145. data/spec/factories/process_times.rb +27 -0
  146. data/spec/factories/processings.rb +25 -0
  147. data/spec/factories/projects.rb +29 -0
  148. data/spec/factories/ranges.rb +35 -0
  149. data/spec/factories/ranges_snapshot.rb +26 -0
  150. data/spec/factories/reading_groups.rb +23 -0
  151. data/spec/factories/readings.rb +25 -0
  152. data/spec/factories/repositories.rb +34 -0
  153. data/spec/factories/repository_observers.rb +24 -0
  154. data/spec/factories/stack_trace_elements.rb +24 -0
  155. data/spec/factories/throwables.rb +23 -0
  156. data/spec/helpers/aggregation_options_spec.rb +31 -0
  157. data/spec/helpers/hash_converters_spec.rb +111 -0
  158. data/spec/helpers/xml_converters_spec.rb +64 -0
  159. data/spec/kalibro_entities_spec.rb +108 -0
  160. data/spec/savon/fixtures/config.yml +1 -0
  161. data/spec/savon/fixtures/invalid_config.yml +2 -0
  162. data/spec/savon/fixtures/project/does_not_exists.xml +1 -0
  163. data/spec/savon/savon_test_helper.rb +14 -0
  164. data/spec/spec_helper.rb +56 -0
  165. metadata +466 -0
@@ -0,0 +1,72 @@
1
+ # This file is part of KalibroGatekeeperClient
2
+ # Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require "kalibro_gatekeeper_client/entities/model"
18
+
19
+ module KalibroGatekeeperClient
20
+ module Entities
21
+ class MetricResult < Model
22
+
23
+ attr_accessor :id, :configuration, :value, :aggregated_value
24
+
25
+ def initialize(attributes={})
26
+ value = attributes[:value]
27
+ @value = (value == "NaN") ? attributes[:aggregated_value].to_f : value.to_f
28
+ attributes.each do |field, value|
29
+ if field!= :value and field!= :aggregated_value and self.class.is_valid?(field)
30
+ send("#{field}=", value)
31
+ end
32
+ end
33
+ @kalibro_errors = []
34
+ end
35
+
36
+ def id=(value)
37
+ @id = value.to_i
38
+ end
39
+
40
+ def configuration=(value)
41
+ @configuration = KalibroGatekeeperClient::Entities::MetricConfigurationSnapshot.to_object value
42
+ end
43
+
44
+ def metric_configuration_snapshot
45
+ @configuration
46
+ end
47
+
48
+ def value=(value)
49
+ @value = value.to_f
50
+ end
51
+
52
+ def aggregated_value=(value)
53
+ @aggregated_value = value.to_i
54
+ end
55
+
56
+ def descendant_results
57
+ descendant_results = self.class.request('descendant_results_of', {id: id})['descendant_results']
58
+ descendant_results.map {|descendant_result| descendant_result.to_f}
59
+ end
60
+
61
+ def self.metric_results_of(module_result_id)
62
+ create_objects_array_from_hash self.request('of', {module_result_id: module_result_id})['metric_results']
63
+ end
64
+
65
+ def self.history_of(metric_name, module_result_id)
66
+ response = self.request('history_of_metric', {:metric_name => metric_name,
67
+ :module_result_id => module_result_id})['date_metric_results']
68
+ create_array_from_hash(response).map { |date_metric_result| KalibroGatekeeperClient::Entities::DateMetricResult.new date_metric_result }
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,174 @@
1
+ # This file is part of KalibroGatekeeperClient
2
+ # Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require 'faraday_middleware'
18
+ require 'kalibro_gatekeeper_client/helpers/hash_converters'
19
+ require 'kalibro_gatekeeper_client/helpers/request_methods'
20
+
21
+ module KalibroGatekeeperClient
22
+ module Entities
23
+ class Model
24
+ attr_accessor :kalibro_errors
25
+
26
+ def initialize(attributes={})
27
+ attributes.each { |field, value| send("#{field}=", value) if self.class.is_valid?(field) }
28
+ @kalibro_errors = []
29
+ end
30
+
31
+ def to_hash(options={})
32
+ hash = Hash.new
33
+ excepts = options[:except].nil? ? [] : options[:except]
34
+ excepts << :kalibro_errors
35
+ fields.each do |field|
36
+ hash = field_to_hash(field).merge(hash) if !excepts.include?(field)
37
+ end
38
+ hash
39
+ end
40
+
41
+ def self.request(action, params = {}, method = :post)
42
+ client.send(method, "/#{endpoint}/#{action}", params).body
43
+ end
44
+
45
+ def self.to_object value
46
+ value.kind_of?(Hash) ? new(value) : value
47
+ end
48
+
49
+ def self.to_objects_array value
50
+ array = value.kind_of?(Array) ? value : [value]
51
+ array.each.map { |element| to_object(element) }
52
+ end
53
+
54
+ def save
55
+ begin
56
+ self.id = self.class.request(save_action, save_params)["id"]
57
+ true
58
+ rescue Exception => exception
59
+ add_error exception
60
+ false
61
+ end
62
+ end
63
+
64
+ def save!
65
+ save
66
+ end
67
+
68
+ def self.create(attributes={})
69
+ new_model = new attributes
70
+ new_model.save
71
+ new_model
72
+ end
73
+
74
+ def ==(another)
75
+ unless self.class == another.class then
76
+ return false
77
+ end
78
+ self.variable_names.each {
79
+ |name|
80
+ unless self.send("#{name}") == another.send("#{name}") then
81
+ return false
82
+ end
83
+ }
84
+ true
85
+ end
86
+
87
+ def self.exists?(id)
88
+ request(exists_action, id_params(id))['exists']
89
+ end
90
+
91
+ def self.find(id)
92
+ if(exists?(id))
93
+ new request(find_action, id_params(id))
94
+ else
95
+ raise KalibroGatekeeperClient::Errors::RecordNotFound
96
+ end
97
+ end
98
+
99
+ def destroy
100
+ begin
101
+ self.class.request(destroy_action, destroy_params)
102
+ rescue Exception => exception
103
+ add_error exception
104
+ end
105
+ end
106
+
107
+ def self.create_objects_array_from_hash (response)
108
+ create_array_from_hash(response).map { |hash| new hash }
109
+ end
110
+
111
+ def self.create_array_from_hash (response)
112
+ response = [] if response.nil?
113
+ response = [response] if response.is_a?(Hash)
114
+ response
115
+ end
116
+
117
+ protected
118
+
119
+ def instance_variable_names
120
+ instance_variables.map { |var| var.to_s }
121
+ end
122
+
123
+ def fields
124
+ instance_variable_names.each.collect { |variable| variable.to_s.sub(/@/, '').to_sym }
125
+ end
126
+
127
+ def variable_names
128
+ instance_variable_names.each.collect { |variable| variable.to_s.sub(/@/, '') }
129
+ end
130
+
131
+ # TODO: probably the connection could be a class static variable.
132
+ def self.client
133
+ Faraday.new(:url => KalibroGatekeeperClient.config[:address]) do |conn|
134
+ conn.request :json
135
+ conn.response :json, :content_type => /\bjson$/
136
+ conn.adapter Faraday.default_adapter # make requests with Net::HTTP
137
+ end
138
+ end
139
+
140
+ def self.is_valid?(field)
141
+ field.to_s[0] != '@' and field != :attributes! and (field =~ /attributes!/).nil? and (field.to_s =~ /xsi/).nil?
142
+ end
143
+
144
+ # TODO: Rename to entitie_name
145
+ def instance_class_name
146
+ self.class.class_name
147
+ end
148
+
149
+ include RequestMethods
150
+ extend RequestMethods::ClassMethods
151
+
152
+ def add_error(exception)
153
+ @kalibro_errors << exception
154
+ end
155
+
156
+ def self.endpoint
157
+ class_name.pluralize.underscore
158
+ end
159
+
160
+ # TODO: Rename to entitie_name
161
+ def self.class_name
162
+ # This loop is a generic way to make this work even when the children class has a different name
163
+ entitie_class = self
164
+ until entitie_class.name.include?("KalibroGatekeeperClient::Entities::") do
165
+ entitie_class = entitie_class.superclass
166
+ end
167
+
168
+ entitie_class.name.gsub(/KalibroGatekeeperClient::Entities::/,"")
169
+ end
170
+
171
+ include HashConverters
172
+ end
173
+ end
174
+ end
@@ -0,0 +1,27 @@
1
+ # This file is part of KalibroGatekeeperClient
2
+ # Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require "kalibro_gatekeeper_client/entities/model"
18
+
19
+ module KalibroGatekeeperClient
20
+ module Entities
21
+ class Module < Model
22
+
23
+ attr_accessor :name, :granularity
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,75 @@
1
+ # This file is part of KalibroGatekeeperClient
2
+ # Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require "kalibro_gatekeeper_client/entities/model"
18
+
19
+ module KalibroGatekeeperClient
20
+ module Entities
21
+ class ModuleResult < Model
22
+
23
+ attr_accessor :id, :module, :grade, :parent_id, :height
24
+
25
+ def self.find(id)
26
+ response = request('get', { id: id })
27
+ raise KalibroGatekeeperClient::Errors::RecordNotFound unless response['error'].nil?
28
+ new response
29
+ end
30
+
31
+ def children
32
+ response = self.class.request('children_of', {id: id})['module_results']
33
+ self.class.create_objects_array_from_hash(response)
34
+ end
35
+
36
+ def parents
37
+ if parent_id == 0
38
+ []
39
+ else
40
+ parent = self.class.find(parent_id)
41
+ parent.parents << parent
42
+ end
43
+ end
44
+
45
+ def id=(value)
46
+ @id = value.to_i
47
+ end
48
+
49
+ def module=(value)
50
+ @module = KalibroGatekeeperClient::Entities::Module.to_object value
51
+ end
52
+
53
+ def grade=(value)
54
+ @grade = value.to_f
55
+ end
56
+
57
+ def parent_id=(value)
58
+ @parent_id = value.to_i
59
+ end
60
+
61
+ def folder?
62
+ self.children.count > 0
63
+ end
64
+
65
+ def file?
66
+ !self.folder?
67
+ end
68
+
69
+ def self.history_of(module_result_id)
70
+ response = self.create_array_from_hash(self.request('history_of', {id: module_result_id})['date_module_results'])
71
+ response.map {|date_module_result| KalibroGatekeeperClient::Entities::DateModuleResult.new date_module_result}
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,31 @@
1
+ # This file is part of KalibroGatekeeperClient
2
+ # Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require "kalibro_gatekeeper_client/entities/model"
18
+
19
+ module KalibroGatekeeperClient
20
+ module Entities
21
+ class ProcessTime < Model
22
+
23
+ attr_accessor :state, :time
24
+
25
+ def time=(time)
26
+ @time = time.to_i
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,113 @@
1
+ # This file is part of KalibroGatekeeperClient
2
+ # Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require "kalibro_gatekeeper_client/entities/model"
18
+
19
+ module KalibroGatekeeperClient
20
+ module Entities
21
+ class Processing < Model
22
+
23
+ attr_accessor :id, :date, :state, :error, :process_time, :results_root_id
24
+
25
+ def id=(value)
26
+ @id = value.to_i
27
+ end
28
+
29
+ def date=(value)
30
+ @date = value.is_a?(String) ? DateTime.parse(value) : value
31
+ end
32
+
33
+ def process_times=(value)
34
+ @process_time = value
35
+ end
36
+
37
+ def process_time=(value)
38
+ @process_time = KalibroGatekeeperClient::Entities::ProcessTime.to_objects_array value
39
+ end
40
+
41
+ def process_times
42
+ @process_time
43
+ end
44
+
45
+ def error=(value)
46
+ @error = KalibroGatekeeperClient::Entities::Throwable.to_object value
47
+ end
48
+
49
+ def results_root_id=(value)
50
+ @results_root_id = value.to_i
51
+ end
52
+
53
+ def self.processing_of(repository_id)
54
+ if has_ready_processing(repository_id)
55
+ last_ready_processing_of(repository_id)
56
+ else
57
+ last_processing_of(repository_id)
58
+ end
59
+ end
60
+
61
+ def self.processing_with_date_of(repository_id, date)
62
+ date = date.is_a?(String) ? DateTime.parse(date) : date
63
+ if has_processing_after(repository_id, date)
64
+ first_processing_after(repository_id, date)
65
+ elsif has_processing_before(repository_id, date)
66
+ last_processing_before(repository_id, date)
67
+ else
68
+ nil
69
+ end
70
+ end
71
+
72
+ def self.has_processing(repository_id)
73
+ request('has', {repository_id: repository_id})['exists']
74
+ end
75
+
76
+ def self.has_ready_processing(repository_id)
77
+ request('has_ready', {repository_id: repository_id})['exists']
78
+ end
79
+
80
+ def self.has_processing_after(repository_id, date)
81
+ request('has_after', {repository_id: repository_id, :date => date})['exists']
82
+ end
83
+
84
+ def self.has_processing_before(repository_id, date)
85
+ request('has_before', {repository_id: repository_id, :date => date})['exists']
86
+ end
87
+
88
+ def self.last_processing_state_of(repository_id)
89
+ request('last_state_of', {repository_id: repository_id})['state']
90
+ end
91
+
92
+ def self.last_ready_processing_of(repository_id)
93
+ new(request('last_ready_of', {repository_id: repository_id})['processing'])
94
+ end
95
+
96
+ def self.first_processing_of(repository_id)
97
+ new(request('first_of', {repository_id: repository_id})['processing'])
98
+ end
99
+
100
+ def self.last_processing_of(repository_id)
101
+ new(request('last_of', {repository_id: repository_id})['processing'])
102
+ end
103
+
104
+ def self.first_processing_after(repository_id, date)
105
+ new(request('first_after_of', {repository_id: repository_id, :date => date})['processing'])
106
+ end
107
+
108
+ def self.last_processing_before(repository_id, date)
109
+ new(request('last_before_of', {repository_id: repository_id, :date => date})['processing'])
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,35 @@
1
+ # This file is part of KalibroGatekeeperClient
2
+ # Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require "kalibro_gatekeeper_client/entities/model"
18
+
19
+ module KalibroGatekeeperClient
20
+ module Entities
21
+ class Project < Model
22
+
23
+ attr_accessor :id, :name, :description
24
+
25
+ def id=(value)
26
+ @id = value.to_i
27
+ end
28
+
29
+ def self.all
30
+ # FIXME: for some reason, the JSON is not getting automatically parsed
31
+ create_objects_array_from_hash(JSON.parse(request('all', {}, :get))["projects"])
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,100 @@
1
+ # This file is part of KalibroGatekeeperClient
2
+ # Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require "kalibro_gatekeeper_client/entities/model"
18
+
19
+ module KalibroGatekeeperClient
20
+ module Entities
21
+ class Range < Model
22
+
23
+ attr_accessor :id, :beginning, :end, :reading_id, :comments, :metric_configuration_id
24
+
25
+ def id=(value)
26
+ @id = value.to_i
27
+ end
28
+
29
+ def reading_id=(value)
30
+ @reading_id = value.to_i
31
+ end
32
+
33
+ def beginning=(value)
34
+ @beginning = value == "-INF" ? value : value.to_f
35
+ end
36
+
37
+ def end=(value)
38
+ @end = value == "INF" ? value : value.to_f
39
+ end
40
+
41
+ def label
42
+ reading.label
43
+ end
44
+
45
+ def grade
46
+ reading.grade
47
+ end
48
+
49
+ def color
50
+ reading.color
51
+ end
52
+
53
+ def self.ranges_of(metric_configuration_id)
54
+ self.create_objects_array_from_hash request('of', {metric_configuration_id: metric_configuration_id} )['ranges']
55
+ end
56
+
57
+ def self.all
58
+ metric_configurations = []
59
+ ranges = []
60
+ configurations = Configuration.all
61
+
62
+ configurations.each do |config|
63
+ metric_configurations.concat(MetricConfiguration.metric_configurations_of(config.id))
64
+ end
65
+
66
+ metric_configurations.each do |metric_config|
67
+ ranges.concat(self.ranges_of(metric_config.id))
68
+ end
69
+
70
+ return ranges
71
+ end
72
+
73
+ def self.find(id)
74
+ self.all.each do |range|
75
+ return range if range.id == id
76
+ end
77
+ raise KalibroGatekeeperClient::Errors::RecordNotFound
78
+ end
79
+
80
+ def self.exists?(id)
81
+ begin
82
+ return true unless self.find(id).nil?
83
+ rescue KalibroGatekeeperClient::Errors::RecordNotFound
84
+ return false
85
+ end
86
+ end
87
+
88
+ private
89
+
90
+ def save_params
91
+ {range: self.to_hash, metric_configuration_id: self.metric_configuration_id}
92
+ end
93
+
94
+ def reading
95
+ @reading ||= KalibroGatekeeperClient::Entities::Reading.find(reading_id)
96
+ @reading
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,37 @@
1
+ # This file is part of KalibroGatekeeperClient
2
+ # Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require "kalibro_gatekeeper_client/entities/model"
18
+
19
+ module KalibroGatekeeperClient
20
+ module Entities
21
+ class RangeSnapshot < Model
22
+ attr_accessor :beginning, :end, :label, :grade, :color, :comments
23
+
24
+ def beginning=(value)
25
+ @beginning = ((value == "-INF") ? -1.0/0 : value.to_f)
26
+ end
27
+
28
+ def end=(value)
29
+ @end = ((value == "INF") ? 1.0/0 : value.to_f)
30
+ end
31
+
32
+ def grade=(value)
33
+ @grade = value.to_f
34
+ end
35
+ end
36
+ end
37
+ end