epb_view_models 1.0.12 → 1.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/Gemfile +10 -10
- data/Gemfile.lock +32 -39
- data/api/schemas/data/orchestrate.json +4 -0
- data/api/schemas/xml/SAP-Schema-19.0.0/SAP/ExternalDefinitions.xml +1352 -0
- data/api/schemas/xml/SAP-Schema-19.0.0/SAP/ExternalDefinitions.xsd +236 -0
- data/api/schemas/xml/SAP-Schema-19.0.0/SAP/Templates/AssessorManagement.xsd +207 -0
- data/api/schemas/xml/SAP-Schema-19.0.0/SAP/Templates/EPC-Certificate.xsd +476 -0
- data/api/schemas/xml/SAP-Schema-19.0.0/SAP/Templates/ExceptionList.xsd +18 -0
- data/api/schemas/xml/SAP-Schema-19.0.0/SAP/Templates/Property.xsd +71 -0
- data/api/schemas/xml/SAP-Schema-19.0.0/SAP/Templates/ReportList.xsd +25 -0
- data/api/schemas/xml/SAP-Schema-19.0.0/SAP/Templates/SAP-CollectedData.xsd +1793 -0
- data/api/schemas/xml/SAP-Schema-19.0.0/SAP/Templates/SAP-Compliance-Report.xsd +36 -0
- data/api/schemas/xml/SAP-Schema-19.0.0/SAP/Templates/SAP-Report.xsd +196 -0
- data/api/schemas/xml/SAP-Schema-19.0.0/SAP/UDT/EPC-Domains.xsd +558 -0
- data/api/schemas/xml/SAP-Schema-19.0.0/SAP/UDT/SAP-Domains.xsd +3127 -0
- data/lib/epb_view_models.rb +1 -1
- data/lib/presenter/ac_cert/export_configuration.rb +7 -0
- data/lib/presenter/ac_report/export_configuration.rb +7 -0
- data/lib/presenter/cepc/export_configuration.rb +7 -0
- data/lib/presenter/cepc_rr/export_configuration.rb +7 -0
- data/lib/presenter/dec/export_configuration.rb +7 -0
- data/lib/presenter/dec_rr/export_configuration.rb +7 -0
- data/lib/presenter/export/statistics.rb +18 -0
- data/lib/presenter/rd_sap/export_configuration.rb +57 -0
- data/lib/presenter/sap/export_configuration.rb +7 -0
- data/lib/presenter/to_warehouse/base_configuration.rb +23 -0
- data/lib/presenter/xml/parser.rb +226 -0
- data/lib/view_model/factory.rb +1 -0
- data/lib/view_model/sap_schema_1900/common_schema.rb +587 -0
- data/lib/view_model/sap_wrapper.rb +2 -0
- data/lib/view_model_gateway/xsd_files_gateway.rb +4 -3
- metadata +26 -2
data/lib/epb_view_models.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
module Presenter::Export
|
2
|
+
class Statistics
|
3
|
+
def initialize(wrapper)
|
4
|
+
@wrapper = wrapper
|
5
|
+
@view_model = wrapper.view_model
|
6
|
+
end
|
7
|
+
|
8
|
+
def build
|
9
|
+
{
|
10
|
+
transaction_type: @view_model.transaction_type,
|
11
|
+
}
|
12
|
+
rescue NoMethodError
|
13
|
+
{
|
14
|
+
transaction_type: 0,
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Presenter
|
2
|
+
module RdSap
|
3
|
+
class ExportConfiguration < Presenter::ToWarehouse::BaseConfiguration
|
4
|
+
excludes %w[
|
5
|
+
ExternalDefinitions-Revision-Number
|
6
|
+
User-Interface-Name
|
7
|
+
User-Interface-Version
|
8
|
+
PCDF-Revision-Number
|
9
|
+
Related-Party-Disclosure
|
10
|
+
Insurance-Details
|
11
|
+
Previous-EPC-Check
|
12
|
+
Green-Deal-Package
|
13
|
+
Energy-Assessor
|
14
|
+
Green-Deal-Category
|
15
|
+
RRN
|
16
|
+
]
|
17
|
+
includes %w[
|
18
|
+
Certificate-Number
|
19
|
+
]
|
20
|
+
bases %w[
|
21
|
+
Report-Header
|
22
|
+
Energy-Assessment
|
23
|
+
Property-Summary
|
24
|
+
Energy-Use
|
25
|
+
SAP-Data
|
26
|
+
SAP-Property-Details
|
27
|
+
Identification-Number
|
28
|
+
Property
|
29
|
+
Address
|
30
|
+
]
|
31
|
+
preferred_keys({
|
32
|
+
"Certificate-Number" => "scheme_assessor_id",
|
33
|
+
})
|
34
|
+
list_nodes %w[
|
35
|
+
SAP-Floor-Dimensions
|
36
|
+
LZC-Energy-Source
|
37
|
+
ImprovementTexts
|
38
|
+
SAP-Building-Parts
|
39
|
+
SAP-Windows
|
40
|
+
SAP-Deselected-Improvements
|
41
|
+
Main-Heating-Details
|
42
|
+
Storage-Heaters
|
43
|
+
SAP-Special-Features
|
44
|
+
Air-Change-Rates
|
45
|
+
PV-Arrays
|
46
|
+
]
|
47
|
+
rootless_list_nodes({
|
48
|
+
"Wall" => "walls",
|
49
|
+
"Roof" => "roofs",
|
50
|
+
"Floor" => { parents: %w[Property-Summary], key: "floors" },
|
51
|
+
"Main-Heating" => { parents: %w[Property-Summary], key: "main-heating" },
|
52
|
+
"Main-Heating-Controls" => "main_heating_controls",
|
53
|
+
"Addendum-Number" => "addendum_numbers",
|
54
|
+
})
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Presenter
|
2
|
+
module ToWarehouse
|
3
|
+
class BaseConfiguration
|
4
|
+
def to_args
|
5
|
+
self.class.args
|
6
|
+
end
|
7
|
+
|
8
|
+
class << self
|
9
|
+
KEYS = %i[excludes includes bases preferred_keys list_nodes rootless_list_nodes].freeze
|
10
|
+
|
11
|
+
KEYS.each do |key|
|
12
|
+
define_method key do |arg|
|
13
|
+
args[key] = arg
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def args
|
18
|
+
@args ||= {}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,226 @@
|
|
1
|
+
module Presenter
|
2
|
+
module Xml
|
3
|
+
class Parser
|
4
|
+
def initialize(excludes: [], includes: [], bases: [], preferred_keys: {}, list_nodes: [], rootless_list_nodes: {})
|
5
|
+
@excludes = excludes
|
6
|
+
@includes = includes
|
7
|
+
@bases = bases
|
8
|
+
@preferred_keys = preferred_keys
|
9
|
+
@list_nodes = list_nodes
|
10
|
+
@rootless_list_nodes = rootless_list_nodes
|
11
|
+
end
|
12
|
+
|
13
|
+
def parse(xml)
|
14
|
+
sax_parser.parse xml
|
15
|
+
last_output
|
16
|
+
end
|
17
|
+
|
18
|
+
def sax_parser
|
19
|
+
@assessment_document ||= AssessmentDocument.new excludes: @excludes,
|
20
|
+
includes: @includes,
|
21
|
+
bases: @bases,
|
22
|
+
preferred_keys: @preferred_keys,
|
23
|
+
list_nodes: @list_nodes,
|
24
|
+
rootless_list_nodes: @rootless_list_nodes
|
25
|
+
@sax_parser ||= Nokogiri::XML::SAX::Parser.new @assessment_document
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def last_output
|
31
|
+
@assessment_document.output
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class AssessmentDocument < Nokogiri::XML::SAX::Document
|
36
|
+
def initialize(excludes: [], includes: [], bases: [], preferred_keys: {}, list_nodes: [], rootless_list_nodes: {})
|
37
|
+
@excludes = excludes
|
38
|
+
@includes = includes
|
39
|
+
@bases = bases
|
40
|
+
@preferred_keys = preferred_keys
|
41
|
+
@list_nodes = list_nodes
|
42
|
+
@rootless_list_nodes = rootless_list_nodes
|
43
|
+
super()
|
44
|
+
end
|
45
|
+
|
46
|
+
def start_document
|
47
|
+
init!
|
48
|
+
@output = {}
|
49
|
+
end
|
50
|
+
|
51
|
+
def end_document
|
52
|
+
init!
|
53
|
+
end
|
54
|
+
|
55
|
+
def start_element_namespace(name, attrs = nil, _prefix = nil, _uri = nil, _namespace = nil)
|
56
|
+
@source_position << name
|
57
|
+
@output_position << root_key_for_list if at_rootless_list_node_item?
|
58
|
+
@output_position << as_key(name) unless is_base?(name)
|
59
|
+
@is_excluding = true if @excludes.include?(name)
|
60
|
+
@is_including = true if @includes.include?(name)
|
61
|
+
super
|
62
|
+
if encountered_position? || at_list_node_item?
|
63
|
+
set_up_list
|
64
|
+
end
|
65
|
+
write_encounter
|
66
|
+
end
|
67
|
+
|
68
|
+
def start_element(_name, attrs = nil)
|
69
|
+
@attrs = attrs
|
70
|
+
end
|
71
|
+
|
72
|
+
def end_element_namespace(name, _prefix = nil, _uri = nil)
|
73
|
+
@output_position.pop unless is_base?(name)
|
74
|
+
@output_position.pop if at_rootless_list_node_item?
|
75
|
+
@source_position.pop
|
76
|
+
@is_excluding = false if @excludes.include?(name)
|
77
|
+
@is_including = false if @includes.include?(name)
|
78
|
+
end
|
79
|
+
|
80
|
+
def characters(string)
|
81
|
+
if @is_excluding && !@is_including
|
82
|
+
return
|
83
|
+
end
|
84
|
+
|
85
|
+
stripped = string.strip
|
86
|
+
if stripped.length.zero?
|
87
|
+
return
|
88
|
+
end
|
89
|
+
|
90
|
+
value = try_as_number stripped
|
91
|
+
|
92
|
+
if @attrs.length.positive?
|
93
|
+
value = @attrs.to_h.merge({ "value" => value })
|
94
|
+
end
|
95
|
+
|
96
|
+
set_value value
|
97
|
+
end
|
98
|
+
|
99
|
+
attr_reader :output
|
100
|
+
|
101
|
+
private
|
102
|
+
|
103
|
+
def init!
|
104
|
+
@source_position = []
|
105
|
+
@output_position = []
|
106
|
+
@is_excluding = false
|
107
|
+
@is_including = false
|
108
|
+
@attrs = []
|
109
|
+
@encountered = []
|
110
|
+
end
|
111
|
+
|
112
|
+
def as_key(name)
|
113
|
+
if @preferred_keys.key?(name)
|
114
|
+
return @preferred_keys[name]
|
115
|
+
end
|
116
|
+
|
117
|
+
name.downcase.gsub("-", "_")
|
118
|
+
end
|
119
|
+
|
120
|
+
def set_value(value)
|
121
|
+
set_value_with_keys(value, @output_position)
|
122
|
+
end
|
123
|
+
|
124
|
+
def set_value_with_keys(value, keys)
|
125
|
+
prepare_hash keys
|
126
|
+
*key, last = keys
|
127
|
+
|
128
|
+
key.inject(@output, :fetch)[last] = value
|
129
|
+
end
|
130
|
+
|
131
|
+
def value_at(keys)
|
132
|
+
keys.inject(@output, :fetch)
|
133
|
+
rescue IndexError
|
134
|
+
nil
|
135
|
+
end
|
136
|
+
|
137
|
+
def prepare_hash(keys)
|
138
|
+
cursor = @output
|
139
|
+
keys[..-2].each do |key|
|
140
|
+
cursor[key] = {} unless cursor[key] && cursor[key] != ""
|
141
|
+
cursor = cursor[key]
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def is_base?(name)
|
146
|
+
@bases.concat(@excludes).include?(name) || name == @source_position[0]
|
147
|
+
end
|
148
|
+
|
149
|
+
def is_numeric?(string)
|
150
|
+
true if Float(string)
|
151
|
+
rescue StandardError
|
152
|
+
false
|
153
|
+
end
|
154
|
+
|
155
|
+
def is_bool?(string)
|
156
|
+
string == true || string == false || string =~ (/(true|false)$/i) ? true : false
|
157
|
+
end
|
158
|
+
|
159
|
+
def try_as_number(string)
|
160
|
+
return string if is_bool?(string)
|
161
|
+
return string unless is_numeric?(string)
|
162
|
+
|
163
|
+
if string.include?(".")
|
164
|
+
string.to_f
|
165
|
+
else
|
166
|
+
string.to_i
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def write_encounter
|
171
|
+
@encountered << source_position_string
|
172
|
+
end
|
173
|
+
|
174
|
+
def encountered_position?
|
175
|
+
@encountered.include? source_position_string
|
176
|
+
end
|
177
|
+
|
178
|
+
def source_position_string
|
179
|
+
@source_position.join(">")
|
180
|
+
end
|
181
|
+
|
182
|
+
def set_up_list
|
183
|
+
return if @output_position.any? { |x| x.is_a? Integer } && !at_list_node_item?
|
184
|
+
|
185
|
+
candidate_list = value_at @output_position[..-2]
|
186
|
+
|
187
|
+
case candidate_list
|
188
|
+
when Array
|
189
|
+
list_index = candidate_list.length
|
190
|
+
when nil
|
191
|
+
set_value_with_keys([], @output_position[..-2])
|
192
|
+
list_index = 0
|
193
|
+
else
|
194
|
+
set_value_with_keys([candidate_list.values[0]], @output_position[..-2])
|
195
|
+
list_index = 1
|
196
|
+
end
|
197
|
+
|
198
|
+
@output_position[-1] = list_index
|
199
|
+
end
|
200
|
+
|
201
|
+
def at_list_node_item?
|
202
|
+
@list_nodes.include?(@source_position[-2]) || at_rootless_list_node_item?
|
203
|
+
end
|
204
|
+
|
205
|
+
def at_rootless_list_node_item?
|
206
|
+
return unless @rootless_list_nodes.key?(@source_position[-1])
|
207
|
+
|
208
|
+
case value = @rootless_list_nodes[@source_position[-1]]
|
209
|
+
when String
|
210
|
+
true
|
211
|
+
else
|
212
|
+
value[:parents].all? { |val| @source_position.include? val }
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
def root_key_for_list
|
217
|
+
case value = @rootless_list_nodes[@source_position[-1]]
|
218
|
+
when String
|
219
|
+
value
|
220
|
+
else
|
221
|
+
value[:key]
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|