GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 60.5% 332 / 0 / 549
Functions: 63.4% 45 / 0 / 71
Branches: 39.6% 368 / 0 / 930

src/utilities/bcl/RemoteBCL.cpp
Line Branch Exec Source
1 /***********************************************************************************************************************
2 * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC.
3 * See also https://openstudio.net/license
4 ***********************************************************************************************************************/
5
6 #include "LocalBCL.hpp"
7 #include "RemoteBCL.hpp"
8 #include "../core/Assert.hpp"
9 #include "../core/PathHelpers.hpp"
10 #include "../core/StringHelpers.hpp"
11 #include "../core/System.hpp"
12 #include "../core/UnzipFile.hpp"
13 #include "../core/DeprecatedHelpers.hpp"
14
15 #include <httplib.h>
16
17 #include <regex>
18
19 #define REMOTE_PRODUCTION_SERVER "https://bcl.nlr.gov"
20 #define REMOTE_DEVELOPMENT_SERVER "https://bcl-test.nlr.gov"
21
22 namespace {
23
24 40 std::unique_ptr<httplib::Client> makeClient(const std::string& baseUrl, unsigned timeOutSeconds) {
25 40 auto cli = std::make_unique<httplib::Client>(baseUrl);
26
1/1
✓ Branch 2 taken 40 times.
40 cli->enable_server_certificate_verification(false);
27
1/1
✓ Branch 2 taken 40 times.
40 cli->set_follow_location(true);
28
1/1
✓ Branch 2 taken 40 times.
40 cli->set_connection_timeout(static_cast<int>(timeOutSeconds), 0);
29
1/1
✓ Branch 2 taken 40 times.
40 cli->set_read_timeout(static_cast<int>(timeOutSeconds), 0);
30
1/1
✓ Branch 2 taken 40 times.
40 cli->set_write_timeout(static_cast<int>(timeOutSeconds), 0);
31 40 return cli;
32 ✗ }
33
34 } // namespace
35
36 namespace openstudio {
37
38 namespace {
39 // Map legacy API v2.0 bundle names to new API names
40 35 std::string normalizeFilterType(const std::string& filterType) {
41
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 35 times.
35 if (filterType == "nrel_component") {
42 ✗ return "component";
43 }
44
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 35 times.
35 if (filterType == "nrel_measure") {
45 ✗ return "measure";
46 }
47 35 return filterType;
48 }
49
50 // Look up the taxonomy name for a given TID, searching the component or measure taxonomy
51 // based on the normalized filter type. Returns empty string if not found.
52 20 std::string tidToTagName(unsigned tid, const std::string& normalizedFilterType) {
53
2/2
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 2 times.
20 const auto& taxonomy = (normalizedFilterType == "component") ? RemoteBCL::componentTaxonomy() : RemoteBCL::measureTaxonomy();
54
1/2
✓ Branch 5 taken 94 times.
✗ Branch 6 not taken.
94 for (const auto& item : taxonomy) {
55
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 74 times.
94 if (static_cast<unsigned>(item.tid) == tid) {
56
1/1
✓ Branch 1 taken 20 times.
20 return item.full_name;
57 }
58 }
59 ✗ return "";
60 }
61 } // namespace
62
63 2 const std::vector<TaxonomyItem>& RemoteBCL::measureTaxonomy() {
64
65 static const std::vector<TaxonomyItem> result = {
66
67 {.full_name = "Economics", .tid = 1120, .name = "Economics", .children = {1}},
68 {.full_name = "Economics.Life Cycle Cost Analysis", .tid = 1121, .name = "Life Cycle Cost Analysis", .parent = 0},
69
70 {.full_name = "Electric Lighting", .tid = 954, .name = "Electric Lighting", .children = {3, 4}},
71 {.full_name = "Electric Lighting.Electric Lighting Controls", .tid = 965, .name = "Electric Lighting Controls", .parent = 2},
72 {.full_name = "Electric Lighting.Lighting Equipment", .tid = 966, .name = "Lighting Equipment", .parent = 2},
73
74 {.full_name = "Envelope", .tid = 953, .name = "Envelope", .children = {6, 7, 8, 9, 10, 11}},
75 {.full_name = "Envelope.Construction Sets", .tid = 1139, .name = "Construction Sets", .parent = 5},
76 {.full_name = "Envelope.Daylighting", .tid = 961, .name = "Daylighting", .parent = 5},
77 {.full_name = "Envelope.Fenestration", .tid = 960, .name = "Fenestration", .parent = 5},
78 {.full_name = "Envelope.Form", .tid = 962, .name = "Form", .parent = 5},
79 {.full_name = "Envelope.Infiltration", .tid = 963, .name = "Infiltration", .parent = 5},
80 {.full_name = "Envelope.Opaque", .tid = 964, .name = "Opaque", .parent = 5},
81
82 {.full_name = "Equipment", .tid = 955, .name = "Equipment", .children = {13, 14, 15}},
83 {.full_name = "Equipment.Electric Equipment", .tid = 968, .name = "Electric Equipment", .parent = 12},
84 {.full_name = "Equipment.Equipment Controls", .tid = 967, .name = "Equipment Controls", .parent = 12},
85 {.full_name = "Equipment.Gas Equipment", .tid = 1140, .name = "Gas Equipment", .parent = 12},
86
87 {.full_name = "HVAC", .tid = 956, .name = "HVAC", .children = {17, 18, 19, 20, 21, 22, 23, 24}},
88 {.full_name = "HVAC.Cooling", .tid = 971, .name = "Cooling", .parent = 16},
89 {.full_name = "HVAC.Distribution", .tid = 974, .name = "Distribution", .parent = 16},
90 {.full_name = "HVAC.Energy Recovery", .tid = 973, .name = "Energy Recovery", .parent = 16},
91 {.full_name = "HVAC.Heating", .tid = 970, .name = "Heating", .parent = 16},
92 {.full_name = "HVAC.Heat Rejection", .tid = 972, .name = "Heat Rejection", .parent = 16},
93 {.full_name = "HVAC.HVAC Controls", .tid = 969, .name = "HVAC Controls", .parent = 16},
94 {.full_name = "HVAC.Ventilation", .tid = 975, .name = "Ventilation", .parent = 16},
95 {.full_name = "HVAC.Whole System", .tid = 976, .name = "Whole System", .parent = 16},
96
97 {.full_name = "Onsite Power Generation", .tid = 1064, .name = "Onsite Power Generation", .children = {26}},
98 {.full_name = "Onsite Power Generation.Photovoltaic", .tid = 1065, .name = "Photovoltaic", .parent = 25},
99
100 {.full_name = "People", .tid = 1132, .name = "People", .children = {28, 29}},
101 {.full_name = "People.Characteristics", .tid = 1134, .name = "Characteristics", .parent = 27},
102 {.full_name = "People.People Schedules", .tid = 1135, .name = "People Schedules", .parent = 27},
103
104 {.full_name = "Refrigeration", .tid = 957, .name = "Refrigeration", .children = {31, 32, 33, 34, 35}},
105 {.full_name = "Refrigeration.Cases and Walkins", .tid = 1343, .name = "Cases and Walkins", .parent = 30},
106 {.full_name = "Refrigeration.Compressors", .tid = 1344, .name = "Compressors", .parent = 30},
107 {.full_name = "Refrigeration.Condensers", .tid = 1345, .name = "Condensers", .parent = 30},
108 {.full_name = "Refrigeration.Heat Reclaim", .tid = 1346, .name = "Heat Reclaim", .parent = 30},
109 {.full_name = "Refrigeration.Refrigeration Controls", .tid = 1342, .name = "Refrigeration Controls", .parent = 30},
110
111 {.full_name = "Reporting", .tid = 959, .name = "Reporting", .children = {37, 38}},
112 {.full_name = "Reporting.QAQC", .tid = 980, .name = "QAQC", .parent = 36},
113 {.full_name = "Reporting.Troubleshooting", .tid = 981, .name = "Troubleshooting", .parent = 36},
114
115 {.full_name = "Service Water Heating", .tid = 958, .name = "Service Water Heating", .children = {40, 41, 42}},
116 {.full_name = "Service Water Heating.Distribution", .tid = 979, .name = "Distribution", .parent = 39},
117 {.full_name = "Service Water Heating.Water Heating", .tid = 978, .name = "Water Heating", .parent = 39},
118 {.full_name = "Service Water Heating.Water Use", .tid = 977, .name = "Water Use", .parent = 39},
119
120 {.full_name = "Whole Building", .tid = 1136, .name = "Whole Building", .children = {44, 45}},
121 {.full_name = "Whole Building.Space Types", .tid = 1138, .name = "Space Types", .parent = 43},
122 {.full_name = "Whole Building.Whole Building Schedules", .tid = 1137, .name = "Whole Building Schedules", .parent = 43},
123
124
6/11
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 time.
✓ Branch 10 taken 46 times.
✓ Branch 11 taken 1 time.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
50 };
125
126 2 return result;
127 3 }
128
129 18 const std::vector<TaxonomyItem>& RemoteBCL::componentTaxonomy() {
130 static const std::vector<TaxonomyItem> result = {
131 {.full_name = "Construction Assembly", .tid = 127, .name = "Construction Assembly", .children = {1, 5, 13, 20}},
132 {.full_name = "Construction Assembly.Fenestration", .tid = 1315, .name = "Fenestration", .parent = 0, .children = {2, 3, 4}},
133 {.full_name = "Construction Assembly.Fenestration.Door", .tid = 1317, .name = "Door", .parent = 1},
134 {.full_name = "Construction Assembly.Fenestration.Skylight", .tid = 1318, .name = "Skylight", .parent = 1},
135 {.full_name = "Construction Assembly.Fenestration.Window", .tid = 1316, .name = "Window", .parent = 1},
136 {.full_name = "Construction Assembly.Floor", .tid = 152, .name = "Floor", .parent = 0, .children = {6, 7, 8, 9, 10, 11, 12}},
137 {.full_name = "Construction Assembly.Floor.Attic Floor", .tid = 928, .name = "Attic Floor", .parent = 5},
138 {.full_name = "Construction Assembly.Floor.Exposed Floor", .tid = 153, .name = "Exposed Floor", .parent = 5},
139 {.full_name = "Construction Assembly.Floor.Exterior Slab", .tid = 154, .name = "Exterior Slab", .parent = 5},
140 {.full_name = "Construction Assembly.Floor.Floor Above Crawlspace", .tid = 899, .name = "Floor Above Crawlspace", .parent = 5},
141 {.full_name = "Construction Assembly.Floor.Floor Above Uncond Bsmt", .tid = 900, .name = "Floor Above Uncond Bsmt", .parent = 5},
142 {.full_name = "Construction Assembly.Floor.Floor Above Uncond Garage", .tid = 901, .name = "Floor Above Uncond Garage", .parent = 5},
143 {.full_name = "Construction Assembly.Floor.Interior Floor", .tid = 927, .name = "Interior Floor", .parent = 5},
144 {.full_name = "Construction Assembly.Roof Ceiling", .tid = 134, .name = "Roof Ceiling", .parent = 0, .children = {14, 15, 16, 17, 18, 19}},
145 {.full_name = "Construction Assembly.Roof Ceiling.Attic Roof", .tid = 887, .name = "Attic Roof", .parent = 13},
146 {.full_name = "Construction Assembly.Roof Ceiling.Crawlspace Ceiling", .tid = 931, .name = "Crawlspace Ceiling", .parent = 13},
147 {.full_name = "Construction Assembly.Roof Ceiling.Exterior Roof", .tid = 929, .name = "Exterior Roof", .parent = 13},
148 {.full_name = "Construction Assembly.Roof Ceiling.Interior Ceiling", .tid = 930, .name = "Interior Ceiling", .parent = 13},
149 {.full_name = "Construction Assembly.Roof Ceiling.Uncond Bsmt Ceiling", .tid = 932, .name = "Uncond Bsmt Ceiling", .parent = 13},
150 {.full_name = "Construction Assembly.Roof Ceiling.Uncond Garage Ceiling", .tid = 933, .name = "Uncond Garage Ceiling", .parent = 13},
151 {.full_name = "Construction Assembly.Wall", .tid = 129, .name = "Wall", .parent = 0, .children = {21, 22, 23}},
152 {.full_name = "Construction Assembly.Wall.Below Grade Wall", .tid = 131, .name = "Below Grade Wall", .parent = 20},
153 {.full_name = "Construction Assembly.Wall.Exterior Wall", .tid = 130, .name = "Exterior Wall", .parent = 20},
154 {.full_name = "Construction Assembly.Wall.Interior Wall", .tid = 132, .name = "Interior Wall", .parent = 20},
155
156 {.full_name = "Electric Lighting", .tid = 946, .name = "Electric Lighting", .children = {25, 27}},
157 {.full_name = "Electric Lighting.Lamp Ballasts", .tid = 949, .name = "Lamp Ballasts", .parent = 24, .children = {26}},
158 {.full_name = "Electric Lighting.Lamp Ballasts.Lamp Ballasts", .tid = 1110, .name = "Lamp Ballasts", .parent = 25},
159 {.full_name = "Electric Lighting.Lamps", .tid = 947, .name = "Lamps", .parent = 24, .children = {28, 29}},
160 {.full_name = "Electric Lighting.Lamps.Non-SSL Lamps", .tid = 1070, .name = "Non-SSL Lamps", .parent = 27},
161 {.full_name = "Electric Lighting.Lamps.SSL Replacement Lamps", .tid = 1406, .name = "SSL Replacement Lamps", .parent = 27},
162
163 {.full_name = "EmissionFactors", .tid = 265, .name = "EmissionFactors", .children = {31, 32}},
164 {.full_name = "EmissionFactors.Electricity Emission Factors (by State)",
165 .tid = 266,
166 .name = "Electricity Emission Factors (by State)",
167 .parent = 30},
168 {.full_name = "EmissionFactors.FossilFuel Emission Factors (by Type)", .tid = 267, .name = "FossilFuel Emission Factors (by Type)", .parent = 30},
169
170 {.full_name = "HVAC", .tid = 210, .name = "HVAC", .children = {34, 36, 38, 41, 42, 49, 51, 53, 55, 57}},
171 {.full_name = "HVAC.Boilers", .tid = 1340, .name = "Boilers", .parent = 33, .children = {35}},
172 {.full_name = "HVAC.Boilers.Hot-Water Boilers", .tid = 1341, .name = "Hot-Water Boilers", .parent = 34},
173 {.full_name = "HVAC.Compressors", .tid = 1281, .name = "Compressors", .parent = 33, .children = {37}},
174 {.full_name = "HVAC.Compressors.Positive Displacement Refrigeration Compressors",
175 .tid = 1280,
176 .name = "Positive Displacement Refrigeration Compressors",
177 .parent = 36},
178 {.full_name = "HVAC.Ductless Heat Pump", .tid = 1337, .name = "Ductless Heat Pump", .parent = 33, .children = {39, 40}},
179 {.full_name = "HVAC.Ductless Heat Pump.Indoor Unit", .tid = 1338, .name = "Indoor Unit", .parent = 38},
180 {.full_name = "HVAC.Ductless Heat Pump.Outdoor Unit", .tid = 1339, .name = "Outdoor Unit", .parent = 38},
181 {.full_name = "HVAC.Energy Recovery", .tid = 1333, .name = "Energy Recovery", .parent = 33},
182 {.full_name = "HVAC.Fan", .tid = 1282, .name = "Fan", .parent = 33, .children = {43, 44, 45, 46, 47, 48}},
183 {.full_name = "HVAC.Fan.Axial Fan", .tid = 1284, .name = "Axial Fan", .parent = 42},
184 {.full_name = "HVAC.Fan.Centrifugal Fan", .tid = 1283, .name = "Centrifugal Fan", .parent = 42},
185 {.full_name = "HVAC.Fan.Cross Flow Fan", .tid = 1286, .name = "Cross Flow Fan", .parent = 42},
186 {.full_name = "HVAC.Fan.Mixed Flow Fan", .tid = 1285, .name = "Mixed Flow Fan", .parent = 42},
187 {.full_name = "HVAC.Fan.Powered Roof Ventilator", .tid = 1288, .name = "Powered Roof Ventilator", .parent = 42},
188 {.full_name = "HVAC.Fan.Tubular Centrifugal Fan", .tid = 1287, .name = "Tubular Centrifugal Fan", .parent = 42},
189 {.full_name = "HVAC.Hydronic Cooling Equipment", .tid = 1130, .name = "Hydronic Cooling Equipment", .parent = 33, .children = {50}},
190 {.full_name = "HVAC.Hydronic Cooling Equipment.Electrically-Driven Mechanical-Compression Chillers",
191 .tid = 1261,
192 .name = "Electrically-Driven Mechanical-Compression Chillers",
193 .parent = 49},
194 {.full_name = "HVAC.Hydronic Heating Equipment", .tid = 1259, .name = "Hydronic Heating Equipment", .parent = 33, .children = {52}},
195 {.full_name = "HVAC.Hydronic Heating Equipment.Boilers", .tid = 1260, .name = "Boilers", .parent = 51},
196 {.full_name = "HVAC.Motor", .tid = 1265, .name = "Motor", .parent = 33, .children = {54}},
197 {.full_name = "HVAC.Motor.Electric Motor", .tid = 1266, .name = "Electric Motor", .parent = 53},
198 {.full_name = "HVAC.Packaged Unitary Equipment", .tid = 1278, .name = "Packaged Unitary Equipment", .parent = 33, .children = {56}},
199 {.full_name = "HVAC.Packaged Unitary Equipment.Rooftop Units", .tid = 1279, .name = "Rooftop Units", .parent = 55},
200 {.full_name = "HVAC.Pumps", .tid = 231, .name = "Pumps", .parent = 33, .children = {58}},
201 {.full_name = "HVAC.Pumps.Rotodynamic Pumps", .tid = 1125, .name = "Rotodynamic Pumps", .parent = 57},
202
203 {.full_name = "Location-Dependent Component", .tid = 168, .name = "Location-Dependent Component", .children = {60, 61, 62, 63, 64, 65, 66}},
204 {.full_name = "Location-Dependent Component.Cooling Degree Days", .tid = 171, .name = "Cooling Degree Days", .parent = 59},
205 {.full_name = "Location-Dependent Component.Design Day", .tid = 121, .name = "Design Day", .parent = 59},
206 {.full_name = "Location-Dependent Component.Ground Temperature", .tid = 172, .name = "Ground Temperature", .parent = 59},
207 {.full_name = "Location-Dependent Component.Heating Degree Days", .tid = 170, .name = "Heating Degree Days", .parent = 59},
208 {.full_name = "Location-Dependent Component.Site", .tid = 924, .name = "Site", .parent = 59},
209 {.full_name = "Location-Dependent Component.Water Mains Temperature", .tid = 407, .name = "Water Mains Temperature", .parent = 59},
210 {.full_name = "Location-Dependent Component.Weather File", .tid = 169, .name = "Weather File", .parent = 59},
211
212 {.full_name = "Material", .tid = 157, .name = "Material", .children = {68, 69}},
213 {.full_name = "Material.Material Heat and Moisture Transfer", .tid = 158, .name = "Material Heat and Moisture Transfer", .parent = 67},
214 {.full_name = "Material.Opaque", .tid = 936, .name = "Opaque", .parent = 67, .children = {70, 71, 72, 73, 74, 75, 76, 77, 78}},
215 {.full_name = "Material.Opaque.Building Board and Siding", .tid = 937, .name = "Building Board and Siding", .parent = 69},
216 {.full_name = "Material.Opaque.Building Membrane", .tid = 938, .name = "Building Membrane", .parent = 69},
217 {.full_name = "Material.Opaque.Finish Flooring", .tid = 939, .name = "Finish Flooring", .parent = 69},
218 {.full_name = "Material.Opaque.Framing with Cavity", .tid = 945, .name = "Framing with Cavity", .parent = 69},
219 {.full_name = "Material.Opaque.Insulation", .tid = 940, .name = "Insulation", .parent = 69},
220 {.full_name = "Material.Opaque.Masonry", .tid = 943, .name = "Masonry", .parent = 69},
221 {.full_name = "Material.Opaque.Plaster", .tid = 942, .name = "Plaster", .parent = 69},
222 {.full_name = "Material.Opaque.Roofing", .tid = 941, .name = "Roofing", .parent = 69},
223 {.full_name = "Material.Opaque.Solid Wood", .tid = 944, .name = "Solid Wood", .parent = 69},
224
225 {.full_name = "MEL", .tid = 238, .name = "MEL", .children = {80, 97, 98, 102, 110, 113, 116, 130}},
226 {.full_name = "MEL.Appliance",
227 .tid = 421,
228 .name = "Appliance",
229 .parent = 79,
230 .children = {81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96}},
231 {.full_name = "MEL.Appliance.Beverage Fountain", .tid = 1270, .name = "Beverage Fountain", .parent = 80},
232 {.full_name = "MEL.Appliance.Cash Exchange", .tid = 1275, .name = "Cash Exchange", .parent = 80},
233 {.full_name = "MEL.Appliance.Coffee Maker", .tid = 1090, .name = "Coffee Maker", .parent = 80},
234 {.full_name = "MEL.Appliance.Desktop Fan", .tid = 1095, .name = "Desktop Fan", .parent = 80},
235 {.full_name = "MEL.Appliance.Drinking Fountain", .tid = 1269, .name = "Drinking Fountain", .parent = 80},
236 {.full_name = "MEL.Appliance.Food Warmer", .tid = 1274, .name = "Food Warmer", .parent = 80},
237 {.full_name = "MEL.Appliance.Freezer", .tid = 596, .name = "Freezer", .parent = 80},
238 {.full_name = "MEL.Appliance.Ice Machine", .tid = 1096, .name = "Ice Machine", .parent = 80},
239 {.full_name = "MEL.Appliance.Microwave", .tid = 1273, .name = "Microwave", .parent = 80},
240 {.full_name = "MEL.Appliance.Mini-fridge", .tid = 1098, .name = "Mini-fridge", .parent = 80},
241 {.full_name = "MEL.Appliance.Personal Heater", .tid = 1100, .name = "Personal Heater", .parent = 80},
242 {.full_name = "MEL.Appliance.Refrigerated Vending Machine", .tid = 1272, .name = "Refrigerated Vending Machine", .parent = 80},
243 {.full_name = "MEL.Appliance.Refrigerator", .tid = 1104, .name = "Refrigerator", .parent = 80},
244 {.full_name = "MEL.Appliance.Vending Machine", .tid = 1105, .name = "Vending Machine", .parent = 80},
245 {.full_name = "MEL.Appliance.Water Cooler", .tid = 916, .name = "Water Cooler", .parent = 80},
246 {.full_name = "MEL.Appliance.Water Purifier", .tid = 1271, .name = "Water Purifier", .parent = 80},
247 {.full_name = "MEL.Audio", .tid = 411, .name = "Audio", .parent = 79},
248 {.full_name = "MEL.Computer", .tid = 239, .name = "Computer", .parent = 79, .children = {99, 100, 101}},
249 {.full_name = "MEL.Computer.Desktop", .tid = 475, .name = "Desktop", .parent = 98},
250 {.full_name = "MEL.Computer.Integrated Display Computer", .tid = 1097, .name = "Integrated Display Computer", .parent = 98},
251 {.full_name = "MEL.Computer.Notebook", .tid = 478, .name = "Notebook", .parent = 98},
252 {.full_name = "MEL.Display", .tid = 413, .name = "Display", .parent = 79, .children = {103, 104, 105, 106, 107, 108, 109}},
253 {.full_name = "MEL.Display.CRT Monitor", .tid = 484, .name = "CRT Monitor", .parent = 102},
254 {.full_name = "MEL.Display.CRT Television", .tid = 1094, .name = "CRT Television", .parent = 102},
255 {.full_name = "MEL.Display.Digital Photo Frame", .tid = 1268, .name = "Digital Photo Frame", .parent = 102},
256 {.full_name = "MEL.Display.LCD Monitor", .tid = 485, .name = "LCD Monitor", .parent = 102},
257 {.full_name = "MEL.Display.LCD Television", .tid = 1267, .name = "LCD Television", .parent = 102},
258 {.full_name = "MEL.Display.Plasma Television", .tid = 1102, .name = "Plasma Television", .parent = 102},
259 {.full_name = "MEL.Display.Projector", .tid = 1103, .name = "Projector", .parent = 102},
260 {.full_name = "MEL.Imaging and Printing", .tid = 414, .name = "Imaging and Printing", .parent = 79, .children = {111, 112}},
261 {.full_name = "MEL.Imaging and Printing.Network Printer / Fax / Scanner", .tid = 1099, .name = "Network Printer / Fax / Scanner", .parent = 110},
262 {.full_name = "MEL.Imaging and Printing.Personal Printer / Fax / Scanner",
263 .tid = 1101,
264 .name = "Personal Printer / Fax / Scanner",
265 .parent = 110},
266 {.full_name = "MEL.Lighting", .tid = 430, .name = "Lighting", .parent = 79, .children = {114, 115}},
267 {.full_name = "MEL.Lighting.Egress Light", .tid = 1277, .name = "Egress Light", .parent = 113},
268 {.full_name = "MEL.Lighting.Task Light", .tid = 1276, .name = "Task Light", .parent = 113},
269 {.full_name = "MEL.Medical",
270 .tid = 431,
271 .name = "Medical",
272 .parent = 79,
273 .children = {117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129}},
274 {.full_name = "MEL.Medical.Blood Pressure Cuff", .tid = 1352, .name = "Blood Pressure Cuff", .parent = 116},
275 {.full_name = "MEL.Medical.Computed Tomography", .tid = 1350, .name = "Computed Tomography", .parent = 116},
276 {.full_name = "MEL.Medical.Electrosurgical Unit", .tid = 1353, .name = "Electrosurgical Unit", .parent = 116},
277 {.full_name = "MEL.Medical.Exam Bed", .tid = 1354, .name = "Exam Bed", .parent = 116},
278 {.full_name = "MEL.Medical.Exam Chair", .tid = 1355, .name = "Exam Chair", .parent = 116},
279 {.full_name = "MEL.Medical.Exam Light", .tid = 1356, .name = "Exam Light", .parent = 116},
280 {.full_name = "MEL.Medical.Infusion Pump", .tid = 1357, .name = "Infusion Pump", .parent = 116},
281 {.full_name = "MEL.Medical.Magnetic Resonance Imaging", .tid = 1351, .name = "Magnetic Resonance Imaging", .parent = 116},
282 {.full_name = "MEL.Medical.Phototherapy Equipment", .tid = 1358, .name = "Phototherapy Equipment", .parent = 116},
283 {.full_name = "MEL.Medical.Smoke Evaporator", .tid = 1359, .name = "Smoke Evaporator", .parent = 116},
284 {.full_name = "MEL.Medical.Surgical Clipper", .tid = 1360, .name = "Surgical Clipper", .parent = 116},
285 {.full_name = "MEL.Medical.Surgical Light", .tid = 1361, .name = "Surgical Light", .parent = 116},
286 {.full_name = "MEL.Medical.Vital Signs Monitor", .tid = 1362, .name = "Vital Signs Monitor", .parent = 116},
287 {.full_name = "MEL.Personal Care", .tid = 435, .name = "Personal Care", .parent = 79},
288
289 {.full_name = "Occupant", .tid = 935, .name = "Occupant"},
290
291 {.full_name = "On-Site Power Generation", .tid = 249, .name = "On-Site Power Generation", .children = {133}},
292 {.full_name = "On-Site Power Generation.Photovoltaic System",
293 .tid = 250,
294 .name = "Photovoltaic System",
295 .parent = 132,
296 .children = {134, 135, 136, 137}},
297 {.full_name = "On-Site Power Generation.Photovoltaic System.Combiner Box", .tid = 952, .name = "Combiner Box", .parent = 133},
298 {.full_name = "On-Site Power Generation.Photovoltaic System.Inverter", .tid = 950, .name = "Inverter", .parent = 133},
299 {.full_name = "On-Site Power Generation.Photovoltaic System.Photovoltaic Module", .tid = 934, .name = "Photovoltaic Module", .parent = 133},
300 {.full_name = "On-Site Power Generation.Photovoltaic System.Racking System", .tid = 951, .name = "Racking System", .parent = 133},
301
302 {.full_name = "Plumbing", .tid = 1248, .name = "Plumbing", .children = {139}},
303 {.full_name = "Plumbing.Water Fixture", .tid = 1249, .name = "Water Fixture", .parent = 138, .children = {140, 141, 142, 143}},
304 {.full_name = "Plumbing.Water Fixture.Faucet", .tid = 1250, .name = "Faucet", .parent = 139},
305 {.full_name = "Plumbing.Water Fixture.Shower Head", .tid = 1251, .name = "Shower Head", .parent = 139},
306 {.full_name = "Plumbing.Water Fixture.Toilet", .tid = 1252, .name = "Toilet", .parent = 139},
307 {.full_name = "Plumbing.Water Fixture.Urinal", .tid = 1253, .name = "Urinal", .parent = 139},
308
309 {.full_name = "Service Water Heating", .tid = 1334, .name = "Service Water Heating", .children = {145}},
310 {.full_name = "Service Water Heating.Tank Water Heater", .tid = 1335, .name = "Tank Water Heater", .parent = 144, .children = {146}},
311 {.full_name = "Service Water Heating.Tank Water Heater.Heat Pump Water Heater", .tid = 1336, .name = "Heat Pump Water Heater", .parent = 145},
312
313 {.full_name = "Special Days", .tid = 1124, .name = "Special Days"},
314
315 {.full_name = "Whole Building", .tid = 1347, .name = "Whole Building"},
316
6/11
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 14 times.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 4 times.
✓ Branch 10 taken 596 times.
✓ Branch 11 taken 4 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
622 };
317
318 18 return result;
319 12 }
320
321 ✗ std::ostream& operator<<(std::ostream& os, const pugi::xml_document& element) {
322 ✗ element.save(os, " ");
323 ✗ return os;
324 }
325
326 37 RemoteQueryResponse::RemoteQueryResponse(std::shared_ptr<pugi::xml_document>& domDocument) : m_domDocument(domDocument) {}
327
328 37 pugi::xml_node RemoteQueryResponse::root() const {
329 37 return m_domDocument->document_element();
330 }
331
332 ✗ unsigned RemoteBCL::timeOutSeconds() const {
333 ✗ return m_timeOutSeconds;
334 }
335 ✗ bool RemoteBCL::setTimeOutSeconds(unsigned timeOutSeconds) {
336 ✗ if (timeOutSeconds < 10) {
337 ✗ LOG(Error, "Setting a timeout of " << timeOutSeconds << " is too low.");
338 ✗ return false;
339 ✗ } else if (timeOutSeconds < 60) {
340 ✗ LOG(Warn, "Setting a timeout of " << timeOutSeconds << " appears low and you risk failures to download components and measures");
341 }
342 ✗ m_timeOutSeconds = timeOutSeconds;
343 ✗ return true;
344 }
345
346 3 bool RemoteBCL::DownloadFile::open() {
347
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
3 OS_ASSERT(!m_fileName.empty());
348
2/2
✓ Branch 3 taken 3 times.
✓ Branch 7 taken 3 times.
3 m_ofs.open(toString(m_fileName).c_str(), std::ios_base::trunc | std::ios_base::out | std::ios_base::binary);
349 3 return m_ofs.good();
350 }
351
352
1/1
✓ Branch 3 taken 3 times.
3 RemoteBCL::DownloadFile::DownloadFile(openstudio::path t_path) : m_fileName(std::move(t_path)) {}
353
354 3 void RemoteBCL::DownloadFile::flush() {
355
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 if (m_ofs.good()) {
356 3 m_ofs.flush();
357 }
358 3 }
359
360 3 const openstudio::path& RemoteBCL::DownloadFile::fileName() const noexcept {
361 3 return m_fileName;
362 }
363
364 3 void RemoteBCL::DownloadFile::close() {
365 3 m_ofs.close();
366 3 }
367
368 3 void RemoteBCL::DownloadFile::write(const std::string& data) {
369 3 m_ofs.write(data.data(), static_cast<std::streamsize>(data.size()));
370 3 }
371
372 7 RemoteBCL::RemoteBCL()
373
2/2
✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
7 : m_prodAuthKey(LocalBCL::instance().prodAuthKey()),
374
2/2
✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
7 m_devAuthKey(LocalBCL::instance().devAuthKey()),
375 7 m_numResultsPerQuery(10),
376 7 m_lastTotalResults(0),
377 7 validProdAuthKey(false),
378 7 validDevAuthKey(false),
379 14 m_timeOutSeconds(120) {
380
1/1
✓ Branch 1 taken 7 times.
7 useRemoteProductionUrl();
381 7 }
382
383 ///////////////////////////////////////////////////////////////////////////
384 /// Inherited members
385 ///////////////////////////////////////////////////////////////////////////
386
387 ✗ boost::optional<BCLComponent> RemoteBCL::getComponent(const std::string& uid, const std::string& /*versionId*/) const {
388 ✗ bool downloadStarted = const_cast<RemoteBCL*>(this)->downloadComponent(uid);
389 ✗ if (downloadStarted) {
390 ✗ return waitForComponentDownload();
391 }
392 ✗ return boost::none;
393 }
394
395 ✗ boost::optional<BCLMeasure> RemoteBCL::getMeasure(const std::string& uid, const std::string& /*versionId*/) const {
396 ✗ bool downloadStarted = const_cast<RemoteBCL*>(this)->downloadMeasure(uid);
397 ✗ if (downloadStarted) {
398 ✗ return waitForMeasureDownload();
399 }
400 ✗ return boost::none;
401 }
402
403 9 boost::optional<BCLMetaSearchResult> RemoteBCL::metaSearchComponentLibrary(const std::string& searchTerm, const std::string& componentType,
404 const std::string& filterType) const {
405 9 bool searchStarted = const_cast<RemoteBCL*>(this)->startComponentLibraryMetaSearch(searchTerm, componentType, filterType);
406
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (searchStarted) {
407 9 return waitForMetaSearch();
408 }
409 ✗ return boost::none;
410 }
411
412 11 boost::optional<BCLMetaSearchResult> RemoteBCL::metaSearchComponentLibrary(const std::string& searchTerm, const unsigned componentTypeTID,
413 const std::string& filterType) const {
414 11 bool searchStarted = const_cast<RemoteBCL*>(this)->startComponentLibraryMetaSearch(searchTerm, componentTypeTID, filterType);
415
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (searchStarted) {
416 11 return waitForMetaSearch();
417 }
418 ✗ return boost::none;
419 }
420
421 6 std::vector<BCLSearchResult> RemoteBCL::searchComponentLibrary(const std::string& searchTerm, const std::string& componentType,
422 const unsigned page) const {
423 // Perform metaSearch first
424
2/2
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
6 metaSearchComponentLibrary(searchTerm, componentType, "component");
425
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
6 if (lastTotalResults() == 0) {
426 ✗ return {};
427 }
428
429
2/2
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
6 bool searchStarted = const_cast<RemoteBCL*>(this)->startComponentLibrarySearch(searchTerm, componentType, "component", page);
430
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (searchStarted) {
431 6 return waitForSearch();
432 }
433 ✗ return {};
434 }
435
436 8 std::vector<BCLSearchResult> RemoteBCL::searchComponentLibrary(const std::string& searchTerm, const unsigned componentTypeTID,
437 const unsigned page) const {
438 // Perform metaSearch first
439
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
8 metaSearchComponentLibrary(searchTerm, componentTypeTID, "component");
440
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
8 if (lastTotalResults() == 0) {
441 ✗ return {};
442 }
443
444
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
8 bool searchStarted = const_cast<RemoteBCL*>(this)->startComponentLibrarySearch(searchTerm, componentTypeTID, "component", page);
445
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (searchStarted) {
446 8 return waitForSearch();
447 }
448 ✗ return {};
449 }
450
451 ✗ std::vector<BCLSearchResult> RemoteBCL::searchMeasureLibrary(const std::string& searchTerm, const std::string& componentType,
452 const unsigned page) const {
453 // Perform metaSearch first
454 ✗ metaSearchComponentLibrary(searchTerm, componentType, "measure");
455 ✗ if (lastTotalResults() == 0) {
456 ✗ return {};
457 }
458
459 ✗ bool searchStarted = const_cast<RemoteBCL*>(this)->startComponentLibrarySearch(searchTerm, componentType, "measure", page);
460 ✗ if (searchStarted) {
461 ✗ return waitForSearch();
462 }
463 ✗ return {};
464 }
465
466 1 std::vector<BCLSearchResult> RemoteBCL::searchMeasureLibrary(const std::string& searchTerm, const unsigned componentTypeTID,
467 const unsigned page) const {
468 // Perform metaSearch first
469
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 metaSearchComponentLibrary(searchTerm, componentTypeTID, "measure");
470
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
1 if (lastTotalResults() == 0) {
471 ✗ return {};
472 }
473
474
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 bool searchStarted = const_cast<RemoteBCL*>(this)->startComponentLibrarySearch(searchTerm, componentTypeTID, "measure", page);
475
1/2
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
1 if (searchStarted) {
476 1 return waitForSearch();
477 }
478 ✗ return {};
479 }
480
481 ✗ int RemoteBCL::checkForComponentUpdates() {
482 ✗ m_componentsWithUpdates.clear();
483
484 ✗ auto cli = makeClient(remoteUrl(), m_timeOutSeconds);
485 ✗ for (const BCLComponent& component : LocalBCL::instance().components()) {
486 ✗ m_lastSearch.clear();
487 ✗ m_lastRequestSuccess = false;
488
489 ✗ auto res = cli->Get("/api/search/*.xml", httplib::Params{{"fq", "uuid:" + component.uid()}}, httplib::Headers{});
490 ✗ if (res && res->status == 200) {
491 ✗ auto remoteQueryResponse = processReply(res->body);
492 ✗ if (remoteQueryResponse) {
493 ✗ m_lastSearch = processSearchResponse(*remoteQueryResponse);
494 }
495 ✗ m_lastRequestSuccess = true;
496 ✗ } else {
497 ✗ LOG(Error, "checkForComponentUpdates request failed" << (res ? ": HTTP " + std::to_string(res->status) : ""));
498 }
499
500 ✗ if (!m_lastSearch.empty() && m_lastSearch[0].versionId() != component.versionId()) {
501 ✗ m_componentsWithUpdates.push_back(m_lastSearch[0]);
502 }
503 ✗ }
504
505 ✗ return static_cast<int>(m_componentsWithUpdates.size());
506 ✗ }
507
508 ✗ int RemoteBCL::checkForMeasureUpdates() {
509 ✗ m_measuresWithUpdates.clear();
510
511 ✗ auto cli = makeClient(remoteUrl(), m_timeOutSeconds);
512 ✗ for (const BCLMeasure& measure : LocalBCL::instance().measures()) {
513 ✗ m_lastSearch.clear();
514 ✗ m_lastRequestSuccess = false;
515
516 ✗ auto res = cli->Get("/api/search/*.xml", httplib::Params{{"fq", "uuid:" + measure.uid()}}, httplib::Headers{});
517 ✗ if (res && res->status == 200) {
518 ✗ auto remoteQueryResponse = processReply(res->body);
519 ✗ if (remoteQueryResponse) {
520 ✗ m_lastSearch = processSearchResponse(*remoteQueryResponse);
521 }
522 ✗ m_lastRequestSuccess = true;
523 ✗ } else {
524 ✗ LOG(Error, "checkForMeasureUpdates request failed" << (res ? ": HTTP " + std::to_string(res->status) : ""));
525 }
526
527 ✗ if (!m_lastSearch.empty() && m_lastSearch[0].versionId() != measure.versionId()) {
528 ✗ m_measuresWithUpdates.push_back(m_lastSearch[0]);
529 }
530 ✗ }
531
532 ✗ return static_cast<int>(m_measuresWithUpdates.size());
533 ✗ }
534
535 ✗ std::vector<BCLSearchResult> RemoteBCL::componentsWithUpdates() const {
536 ✗ return m_componentsWithUpdates;
537 }
538
539 ✗ std::vector<BCLSearchResult> RemoteBCL::measuresWithUpdates() const {
540 ✗ return m_measuresWithUpdates;
541 }
542
543 ✗ void RemoteBCL::updateComponents() {
544 ✗ if (m_componentsWithUpdates.empty()) {
545 ✗ checkForComponentUpdates();
546 }
547
548 ✗ for (const BCLSearchResult& component : m_componentsWithUpdates) {
549 ✗ downloadComponent(component.uid());
550 ✗ boost::optional<BCLComponent> newComponent = waitForComponentDownload();
551
552 ✗ if (newComponent) {
553 ✗ LocalBCL::instance().removeOutdatedLocalComponents(newComponent->uid(), newComponent->versionId());
554 }
555 ✗ }
556 ✗ }
557
558 ✗ void RemoteBCL::updateMeasures() {
559 ✗ if (m_measuresWithUpdates.empty()) {
560 ✗ checkForMeasureUpdates();
561 }
562
563 ✗ for (const BCLSearchResult& measure : m_measuresWithUpdates) {
564 ✗ downloadMeasure(measure.uid());
565 ✗ boost::optional<BCLMeasure> newMeasure = waitForMeasureDownload();
566
567 ✗ if (newMeasure) {
568 ✗ LocalBCL::instance().removeOutdatedLocalMeasures(newMeasure->uid(), newMeasure->versionId());
569 }
570 ✗ }
571 ✗ }
572
573 ///////////////////////////////////////////////////////////////////////////
574 /// Blocking class members
575 ///////////////////////////////////////////////////////////////////////////
576
577 ✗ bool RemoteBCL::isOnline() {
578 try {
579 ✗ auto cli = makeClient("https://checkip.amazonaws.com", 10);
580
581 ✗ auto res = cli->Get("/");
582 ✗ if (!res || res->status != 200) {
583 ✗ return false;
584 }
585 ✗ std::string ip = res->body;
586 ✗ ip.erase(ip.find_last_not_of("\n\r") + 1);
587 ✗ std::regex ipRegex("^\\d{1,3}(?:\\.\\d{1,3}){3}$");
588 ✗ return std::regex_search(ip, ipRegex);
589 ✗ } catch (const std::exception&) {
590 // not online
591 ✗ }
592 ✗ return false;
593 }
594
595 2 boost::optional<BCLComponent> RemoteBCL::lastComponentDownload() const {
596 2 return m_lastComponentDownload;
597 }
598
599 ✗ boost::optional<BCLMeasure> RemoteBCL::lastMeasureDownload() const {
600 ✗ return m_lastMeasureDownload;
601 }
602
603 ✗ boost::optional<BCLMetaSearchResult> RemoteBCL::lastMetaSearch() const {
604 ✗ return m_lastMetaSearch;
605 }
606
607 ✗ std::vector<BCLSearchResult> RemoteBCL::lastSearch() const {
608 ✗ return m_lastSearch;
609 }
610
611 41 std::string RemoteBCL::remoteUrl() const {
612 41 return m_remoteUrl;
613 }
614
615 16 std::string RemoteBCL::remoteProductionUrl() {
616
1/1
✓ Branch 1 taken 16 times.
32 return {REMOTE_PRODUCTION_SERVER};
617 }
618
619 8 std::string RemoteBCL::remoteDevelopmentUrl() {
620
1/1
✓ Branch 1 taken 8 times.
16 return {REMOTE_DEVELOPMENT_SERVER};
621 }
622
623 ✗ void RemoteBCL::useRemoteDevelopmentUrl() {
624 ✗ m_useRemoteDevelopmentUrl = true;
625 ✗ m_remoteUrl = remoteDevelopmentUrl();
626 ✗ m_authKey = m_devAuthKey;
627 ✗ }
628
629 11 void RemoteBCL::useRemoteProductionUrl() {
630 11 m_useRemoteDevelopmentUrl = false;
631
1/1
✓ Branch 1 taken 11 times.
11 m_remoteUrl = remoteProductionUrl();
632 11 m_authKey = m_prodAuthKey;
633 11 }
634
635 1 std::string RemoteBCL::authKey() const {
636 1 return m_authKey;
637 }
638
639 4 std::string RemoteBCL::prodAuthKey() const {
640 4 return m_prodAuthKey;
641 }
642
643 2 bool RemoteBCL::setProdAuthKey(const std::string& prodAuthKey) {
644 2 bool previousValidity = validProdAuthKey;
645
3/4
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
2 if (validateAuthKey(prodAuthKey, remoteProductionUrl())) {
646 2 m_prodAuthKey = prodAuthKey;
647
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (!m_useRemoteDevelopmentUrl) {
648 2 m_authKey = prodAuthKey;
649 }
650 2 return true;
651 }
652 ✗ validProdAuthKey = previousValidity;
653 ✗ return false;
654 }
655
656 ✗ std::string RemoteBCL::devAuthKey() const {
657 ✗ return m_devAuthKey;
658 }
659
660 ✗ bool RemoteBCL::setDevAuthKey(const std::string& devAuthKey) {
661 ✗ bool previousValidity = validDevAuthKey;
662 ✗ if (validateAuthKey(devAuthKey, remoteDevelopmentUrl())) {
663 ✗ m_devAuthKey = devAuthKey;
664 ✗ if (m_useRemoteDevelopmentUrl) {
665 ✗ m_authKey = devAuthKey;
666 }
667 ✗ return true;
668 }
669 ✗ validDevAuthKey = previousValidity;
670 ✗ return false;
671 }
672
673 4 int RemoteBCL::resultsPerQuery() const {
674 4 return m_numResultsPerQuery;
675 }
676
677 19 int RemoteBCL::lastTotalResults() const {
678 19 return m_lastTotalResults;
679 }
680
681 2 int RemoteBCL::numResultPages() const {
682 2 double numerator(lastTotalResults());
683 2 double denominator(resultsPerQuery());
684 2 return int(std::ceil(numerator / denominator));
685 }
686
687 2 bool RemoteBCL::validateAuthKey(const std::string& authKey, const std::string& remoteUrl) {
688
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 if (authKey.length() == 32) {
689
1/1
✓ Branch 1 taken 2 times.
2 std::string previousUrl = this->remoteUrl();
690
691 // Check if validation has already run for the given key
692
9/18
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 1 time.
✓ Branch 11 taken 1 time.
✗ Branch 12 not taken.
✓ Branch 13 taken 1 time.
✓ Branch 14 taken 2 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 2 times.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 2 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
2 if (remoteUrl == remoteProductionUrl() && authKey == prodAuthKey() && validProdAuthKey) {
693 ✗ return true;
694
5/18
✓ Branch 1 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 7 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 2 times.
✓ Branch 17 taken 2 times.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 2 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
2 } else if (remoteUrl == remoteDevelopmentUrl() && authKey == devAuthKey() && validDevAuthKey) {
695 ✗ return true;
696 }
697
698 // Temporarily set url
699
2/3
✓ Branch 1 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
2 if (remoteUrl == remoteDevelopmentUrl()) {
700 ✗ useRemoteDevelopmentUrl();
701 } else {
702
1/1
✓ Branch 1 taken 2 times.
2 useRemoteProductionUrl();
703 }
704
705 2 m_lastSearch.clear();
706 2 m_lastRequestSuccess = false;
707
708
1/1
✓ Branch 1 taken 2 times.
2 auto cli = makeClient(remoteUrl, m_timeOutSeconds);
709
5/7
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 14 taken 2 times.
✓ Branch 15 taken 2 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
12 auto res = cli->Get("/api/search/*.xml", httplib::Params{{"show_rows", "0"}}, httplib::Headers{});
710
3/6
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
2 if (res && res->status == 200) {
711
1/1
✓ Branch 2 taken 2 times.
2 auto remoteQueryResponse = processReply(res->body);
712
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (remoteQueryResponse) {
713
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 m_lastSearch = processSearchResponse(*remoteQueryResponse);
714 }
715 2 m_lastRequestSuccess = true;
716 2 } else {
717 ✗ LOG(Error, "validateAuthKey request failed" << (res ? ": HTTP " + std::to_string(res->status) : ""));
718 }
719
720 // Restore url
721
2/3
✓ Branch 1 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
2 if (previousUrl == remoteDevelopmentUrl()) {
722 ✗ useRemoteDevelopmentUrl();
723 } else {
724
1/1
✓ Branch 1 taken 2 times.
2 useRemoteProductionUrl();
725 }
726
727
2/3
✓ Branch 1 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
2 if (remoteUrl == remoteDevelopmentUrl()) {
728 ✗ return validDevAuthKey;
729 } else {
730 2 return validProdAuthKey;
731 }
732 2 }
733 ✗ return false;
734 2 }
735
736 3 boost::optional<BCLComponent> RemoteBCL::waitForComponentDownload() const {
737
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 if (waitForLock()) {
738 3 return m_lastComponentDownload;
739 }
740 ✗ return boost::none;
741 }
742
743 ✗ boost::optional<BCLComponent> RemoteBCL::waitForComponentDownload(int) const {
744 ✗ DEPRECATED_AT_MSG(3, 2, 1, "The int parameter is unused. Use waitForComponentDownload() instead");
745 ✗ return waitForComponentDownload();
746 }
747
748 ✗ boost::optional<BCLMeasure> RemoteBCL::waitForMeasureDownload() const {
749 ✗ if (waitForLock()) {
750 ✗ return m_lastMeasureDownload;
751 }
752 ✗ return boost::none;
753 }
754
755 ✗ boost::optional<BCLMeasure> RemoteBCL::waitForMeasureDownload(int) const {
756 ✗ DEPRECATED_AT_MSG(3, 2, 1, "The int parameter is unused. Use waitForMeasureDownload() instead");
757 ✗ return waitForMeasureDownload();
758 }
759
760 25 boost::optional<BCLMetaSearchResult> RemoteBCL::waitForMetaSearch() const {
761
1/2
✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
25 if (waitForLock()) {
762 25 return m_lastMetaSearch;
763 }
764 ✗ return boost::none;
765 }
766
767 ✗ boost::optional<BCLMetaSearchResult> RemoteBCL::waitForMetaSearch(int) const {
768 ✗ DEPRECATED_AT_MSG(3, 2, 1, "The int parameter is unused. Use waitForMetaSearch() instead");
769 ✗ return waitForMetaSearch();
770 }
771
772 15 std::vector<BCLSearchResult> RemoteBCL::waitForSearch() const {
773
1/2
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
15 if (waitForLock()) {
774 15 return m_lastSearch;
775 }
776 ✗ return {};
777 }
778
779 ✗ std::vector<BCLSearchResult> RemoteBCL::waitForSearch(int) const {
780 ✗ DEPRECATED_AT_MSG(3, 2, 1, "The int parameter is unused. Use waitForSearch() instead");
781 ✗ return waitForSearch();
782 }
783
784 ///////////////////////////////////////////////////////////////////////////
785 /// Non-blocking class members
786 ///////////////////////////////////////////////////////////////////////////
787
788 3 bool RemoteBCL::downloadComponent(const std::string& uid) {
789
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
3 if (uid.empty()) {
790 ✗ LOG(Error, "Error: No uid provided");
791 ✗ return false;
792 }
793
794
4/4
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
6 m_downloadFile = std::make_unique<DownloadFile>(openstudio::filesystem::temp_directory_path() / toPath(uid + ".bcl"));
795
2/3
✓ Branch 2 taken 3 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 3 times.
3 if (!m_downloadFile->open()) {
796 ✗ return false;
797 }
798
799
1/1
✓ Branch 1 taken 3 times.
3 m_downloadUid = uid;
800 3 m_lastRequestSuccess = false;
801
802
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
3 auto cli = makeClient(remoteUrl(), m_timeOutSeconds);
803
5/7
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
✓ Branch 14 taken 3 times.
✓ Branch 15 taken 3 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
18 auto res = cli->Get("/api/download", httplib::Params{{"uids", uid}}, httplib::Headers{});
804
3/6
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
3 if (res && res->status == 200) {
805
1/1
✓ Branch 3 taken 3 times.
3 m_downloadFile->write(res->body);
806
1/1
✓ Branch 2 taken 3 times.
3 m_downloadFile->flush();
807
1/1
✓ Branch 2 taken 3 times.
3 m_downloadFile->close();
808 3 m_lastRequestSuccess = true;
809
1/1
✓ Branch 1 taken 3 times.
3 onDownloadComplete();
810 } else {
811 ✗ LOG(Error, "downloadComponent request failed" << (res ? ": HTTP " + std::to_string(res->status) : ""));
812 ✗ m_downloadFile->close();
813 }
814
815 3 return m_lastRequestSuccess;
816 6 }
817
818 ✗ bool RemoteBCL::downloadMeasure(const std::string& uid) {
819 ✗ return downloadComponent(uid);
820 }
821
822 9 bool RemoteBCL::startComponentLibraryMetaSearch(const std::string& searchTerm, const std::string& componentType, const std::string& filterType) {
823 9 m_lastMetaSearch.reset();
824 9 m_lastRequestSuccess = false;
825
826
1/1
✓ Branch 1 taken 9 times.
9 const std::string normalizedFilterType = normalizeFilterType(filterType);
827
828
6/8
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 6 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 6 times.
✓ Branch 9 taken 3 times.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
12 std::string query = searchTerm.empty() ? "*" : searchTerm;
829
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 std::string path = "/api/metasearch/" + query + ".xml";
830
831
3/5
✓ Branch 1 taken 9 times.
✓ Branch 3 taken 9 times.
✓ Branch 4 taken 9 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
27 httplib::Params params{{"fq", "bundle:" + normalizedFilterType}};
832
7/7
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 2 times.
✓ Branch 4 taken 7 times.
✓ Branch 6 taken 6 times.
✓ Branch 7 taken 1 time.
✓ Branch 8 taken 6 times.
✓ Branch 9 taken 3 times.
9 if (!componentType.empty() && componentType != "*") {
833
3/4
✓ Branch 1 taken 6 times.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 6 times.
6 std::string tag = (normalizedFilterType == "component") ? "component_tags" : "measure_tags";
834
4/4
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
✓ Branch 10 taken 6 times.
6 params.emplace("fq", tag + ":\"" + componentType + "\"");
835 6 }
836
837
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 auto cli = makeClient(remoteUrl(), m_timeOutSeconds);
838
1/1
✓ Branch 4 taken 9 times.
9 auto res = cli->Get(path, params, httplib::Headers{});
839
3/6
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 9 times.
✗ Branch 7 not taken.
9 if (res && res->status == 200) {
840
1/1
✓ Branch 2 taken 9 times.
9 auto remoteQueryResponse = processReply(res->body);
841
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (remoteQueryResponse) {
842
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 m_lastMetaSearch = processMetaSearchResponse(*remoteQueryResponse);
843 }
844
4/5
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
✓ Branch 10 taken 9 times.
18 setLastTotalResults(m_lastMetaSearch ? m_lastMetaSearch->numResults() : 0);
845 9 m_lastRequestSuccess = true;
846 9 } else {
847 ✗ setLastTotalResults(0);
848 ✗ LOG(Error, "startComponentLibraryMetaSearch request failed" << (res ? ": HTTP " + std::to_string(res->status) : ""));
849 }
850
851 9 return m_lastRequestSuccess;
852 18 }
853
854 11 bool RemoteBCL::startComponentLibraryMetaSearch(const std::string& searchTerm, const unsigned componentTypeTID, const std::string& filterType) {
855 11 m_lastMetaSearch.reset();
856 11 m_lastRequestSuccess = false;
857
858
1/1
✓ Branch 1 taken 11 times.
11 const std::string normalizedFilterType = normalizeFilterType(filterType);
859
860
6/8
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 7 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 7 times.
✓ Branch 9 taken 4 times.
✓ Branch 10 taken 7 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
15 std::string query = searchTerm.empty() ? "*" : searchTerm;
861
2/2
✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
11 std::string path = "/api/metasearch/" + query + ".xml";
862
863
3/5
✓ Branch 1 taken 11 times.
✓ Branch 3 taken 11 times.
✓ Branch 4 taken 11 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
33 httplib::Params params{{"fq", "bundle:" + normalizedFilterType}};
864
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (componentTypeTID != 0) {
865
1/1
✓ Branch 1 taken 11 times.
11 const std::string tagName = tidToTagName(componentTypeTID, normalizedFilterType);
866
1/2
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
11 if (!tagName.empty()) {
867
4/4
✓ Branch 1 taken 11 times.
✓ Branch 3 taken 10 times.
✓ Branch 4 taken 1 time.
✓ Branch 6 taken 11 times.
11 const std::string tagField = (normalizedFilterType == "component") ? "component_tags" : "measure_tags";
868
4/4
✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
✓ Branch 7 taken 11 times.
✓ Branch 10 taken 11 times.
11 params.emplace("fq", tagField + ":\"" + tagName + "\"");
869 11 } else {
870 ✗ LOG(Warn, "Unknown TID " << componentTypeTID << " for bundle '" << normalizedFilterType << "', ignoring tag filter");
871 }
872 11 }
873
874
2/2
✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
11 auto cli = makeClient(remoteUrl(), m_timeOutSeconds);
875
1/1
✓ Branch 4 taken 11 times.
11 auto res = cli->Get(path, params, httplib::Headers{});
876
3/6
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 11 times.
✗ Branch 7 not taken.
11 if (res && res->status == 200) {
877
1/1
✓ Branch 2 taken 11 times.
11 auto remoteQueryResponse = processReply(res->body);
878
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (remoteQueryResponse) {
879
2/2
✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
11 m_lastMetaSearch = processMetaSearchResponse(*remoteQueryResponse);
880 }
881
4/5
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 11 times.
✓ Branch 7 taken 11 times.
✓ Branch 10 taken 11 times.
22 setLastTotalResults(m_lastMetaSearch ? m_lastMetaSearch->numResults() : 0);
882 11 m_lastRequestSuccess = true;
883 11 } else {
884 ✗ setLastTotalResults(0);
885 ✗ LOG(Error, "startComponentLibraryMetaSearch request failed" << (res ? ": HTTP " + std::to_string(res->status) : ""));
886 }
887
888 11 return m_lastRequestSuccess;
889 22 }
890
891 6 bool RemoteBCL::startComponentLibrarySearch(const std::string& searchTerm, const std::string& componentType, const std::string& filterType,
892 const unsigned page) {
893 6 m_lastSearch.clear();
894 6 m_lastRequestSuccess = false;
895
896
1/1
✓ Branch 1 taken 6 times.
6 const std::string normalizedFilterType = normalizeFilterType(filterType);
897
898
6/8
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 5 times.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 5 times.
✓ Branch 9 taken 1 time.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
7 std::string query = searchTerm.empty() ? "*" : searchTerm;
899
2/2
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
6 std::string path = "/api/search/" + query + ".xml";
900
901 ✗ httplib::Params params{{"fq", "bundle:" + normalizedFilterType},
902 6 {"show_rows", openstudio::string_conversions::number(m_numResultsPerQuery)},
903
3/5
✓ Branch 1 taken 6 times.
✓ Branch 3 taken 18 times.
✓ Branch 4 taken 6 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
30 {"page", openstudio::string_conversions::number(page)}};
904
7/7
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 1 time.
✓ Branch 4 taken 5 times.
✓ Branch 6 taken 4 times.
✓ Branch 7 taken 1 time.
✓ Branch 8 taken 4 times.
✓ Branch 9 taken 2 times.
6 if (!componentType.empty() && componentType != "*") {
905
3/4
✓ Branch 1 taken 4 times.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 4 times.
4 std::string tag = (normalizedFilterType == "component") ? "component_tags" : "measure_tags";
906
4/4
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
4 params.emplace("fq", tag + ":\"" + componentType + "\"");
907 4 }
908
909
2/2
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
6 auto cli = makeClient(remoteUrl(), m_timeOutSeconds);
910
1/1
✓ Branch 4 taken 6 times.
6 auto res = cli->Get(path, params, httplib::Headers{});
911
3/6
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
6 if (res && res->status == 200) {
912
1/1
✓ Branch 2 taken 6 times.
6 auto remoteQueryResponse = processReply(res->body);
913
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (remoteQueryResponse) {
914
2/2
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
6 m_lastSearch = processSearchResponse(*remoteQueryResponse);
915 }
916 6 m_lastRequestSuccess = true;
917 6 } else {
918 ✗ LOG(Error, "startComponentLibrarySearch request failed" << (res ? ": HTTP " + std::to_string(res->status) : ""));
919 }
920
921 6 return m_lastRequestSuccess;
922 12 }
923
924 9 bool RemoteBCL::startComponentLibrarySearch(const std::string& searchTerm, const unsigned componentTypeTID, const std::string& filterType,
925 const unsigned page) {
926 9 m_lastSearch.clear();
927 9 m_lastRequestSuccess = false;
928
929
1/1
✓ Branch 1 taken 9 times.
9 const std::string normalizedFilterType = normalizeFilterType(filterType);
930
931
6/8
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 6 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 6 times.
✓ Branch 9 taken 3 times.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
12 std::string query = searchTerm.empty() ? "*" : searchTerm;
932
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 std::string path = "/api/search/" + query + ".xml";
933
934 ✗ httplib::Params params{{"fq", "bundle:" + normalizedFilterType},
935 9 {"show_rows", openstudio::string_conversions::number(m_numResultsPerQuery)},
936
3/5
✓ Branch 1 taken 9 times.
✓ Branch 3 taken 27 times.
✓ Branch 4 taken 9 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
45 {"page", openstudio::string_conversions::number(page)}};
937
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (componentTypeTID != 0) {
938
1/1
✓ Branch 1 taken 9 times.
9 const std::string tagName = tidToTagName(componentTypeTID, normalizedFilterType);
939
1/2
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
9 if (!tagName.empty()) {
940
4/4
✓ Branch 1 taken 9 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 1 time.
✓ Branch 6 taken 9 times.
9 const std::string tagField = (normalizedFilterType == "component") ? "component_tags" : "measure_tags";
941
4/4
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
✓ Branch 10 taken 9 times.
9 params.emplace("fq", tagField + ":\"" + tagName + "\"");
942 9 } else {
943 ✗ LOG(Warn, "Unknown TID " << componentTypeTID << " for bundle '" << normalizedFilterType << "', ignoring tag filter");
944 }
945 9 }
946
947
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 auto cli = makeClient(remoteUrl(), m_timeOutSeconds);
948
1/1
✓ Branch 4 taken 9 times.
9 auto res = cli->Get(path, params, httplib::Headers{});
949
3/6
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 9 times.
✗ Branch 7 not taken.
9 if (res && res->status == 200) {
950
1/1
✓ Branch 2 taken 9 times.
9 auto remoteQueryResponse = processReply(res->body);
951
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (remoteQueryResponse) {
952
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 m_lastSearch = processSearchResponse(*remoteQueryResponse);
953 }
954 9 m_lastRequestSuccess = true;
955 9 } else {
956 ✗ LOG(Error, "startComponentLibrarySearch request failed" << (res ? ": HTTP " + std::to_string(res->status) : ""));
957 }
958
959 9 return m_lastRequestSuccess;
960 18 }
961
962 43 bool RemoteBCL::waitForLock() const {
963 43 return m_lastRequestSuccess;
964 }
965
966 37 boost::optional<RemoteQueryResponse> RemoteBCL::processReply(const std::string& reply) {
967
1/1
✓ Branch 1 taken 37 times.
37 std::shared_ptr<pugi::xml_document> document = std::make_shared<pugi::xml_document>();
968
1/1
✓ Branch 3 taken 37 times.
37 auto result = document->load_string(reply.c_str());
969
2/3
✓ Branch 1 taken 37 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 37 times.
37 if (!result) {
970 ✗ LOG(Error, "Bad XML Response: " << result.description());
971 } else {
972
1/2
✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
37 if (!m_useRemoteDevelopmentUrl) {
973 37 validProdAuthKey = true;
974 } else {
975 ✗ validDevAuthKey = true;
976 }
977
2/2
✓ Branch 1 taken 37 times.
✓ Branch 4 taken 37 times.
37 return RemoteQueryResponse(document);
978 }
979
980 ✗ return boost::none;
981 37 }
982
983 20 boost::optional<BCLMetaSearchResult> RemoteBCL::processMetaSearchResponse(const RemoteQueryResponse& remoteQueryResponse) {
984
1/1
✓ Branch 1 taken 20 times.
20 auto root = remoteQueryResponse.root();
985
986
2/3
✓ Branch 1 taken 20 times.
✓ Branch 3 taken 20 times.
✗ Branch 4 not taken.
20 if (root) {
987
4/5
✓ Branch 1 taken 20 times.
✓ Branch 4 taken 20 times.
✓ Branch 7 taken 20 times.
✓ Branch 10 taken 20 times.
✗ Branch 11 not taken.
40 if (std::string(root.name()).compare(0, 6, "result") == 0) { // C++20: std::string(root.name()).starts_with("result")
988
1/1
✓ Branch 1 taken 20 times.
20 auto numResultsElement = root.child("result_count");
989
2/3
✓ Branch 1 taken 20 times.
✓ Branch 3 taken 20 times.
✗ Branch 4 not taken.
20 if (numResultsElement) {
990
2/2
✓ Branch 1 taken 20 times.
✓ Branch 4 taken 20 times.
20 return BCLMetaSearchResult(root);
991 }
992 }
993 }
994
995 ✗ return boost::none;
996 }
997
998 17 std::vector<BCLSearchResult> RemoteBCL::processSearchResponse(const RemoteQueryResponse& remoteQueryResponse) {
999 17 std::vector<BCLSearchResult> searchResults;
1000
1001
1/1
✓ Branch 1 taken 17 times.
17 auto root = remoteQueryResponse.root();
1002
1/1
✓ Branch 1 taken 17 times.
17 auto result = root.child("result");
1003
3/3
✓ Branch 1 taken 17 times.
✓ Branch 3 taken 15 times.
✓ Branch 4 taken 2 times.
17 if (result) {
1004
1/1
✓ Branch 1 taken 15 times.
15 auto componentElement = result.first_child();
1005
1006 //Basic check to see if it's non-empty
1007
4/4
✓ Branch 1 taken 149 times.
✓ Branch 4 taken 149 times.
✓ Branch 6 taken 134 times.
✓ Branch 7 taken 15 times.
149 while (componentElement.child("name") != nullptr) {
1008 //Skip components without a uid or version_id
1009
7/10
✓ Branch 1 taken 134 times.
✓ Branch 4 taken 134 times.
✓ Branch 6 taken 134 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 134 times.
✓ Branch 12 taken 134 times.
✓ Branch 14 taken 134 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 134 times.
✗ Branch 17 not taken.
134 if ((componentElement.child("uuid") != nullptr) && (componentElement.child("vuuid") != nullptr)) {
1010
1/1
✓ Branch 1 taken 134 times.
134 BCLSearchResult searchResult(componentElement);
1011
1/1
✓ Branch 1 taken 134 times.
134 searchResults.push_back(searchResult);
1012 134 }
1013
1/1
✓ Branch 1 taken 134 times.
134 result = result.next_sibling("result");
1014
1/1
✓ Branch 1 taken 134 times.
134 componentElement = result.first_child();
1015 }
1016 }
1017
1018 34 return searchResults;
1019 ✗ }
1020
1021 3 void RemoteBCL::onDownloadComplete() {
1022
1/1
✓ Branch 3 taken 3 times.
3 const auto src = m_downloadFile->fileName();
1023 3 std::string componentType;
1024
1025 // Extract the files to a temp location
1026
3/3
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
6 openstudio::path tempDest = openstudio::filesystem::temp_directory_path() / toPath(m_downloadUid + '/');
1027
1028
2/3
✓ Branch 1 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
3 if (openstudio::filesystem::is_directory(tempDest)) {
1029 ✗ removeDirectory(tempDest);
1030 }
1031
1/1
✓ Branch 1 taken 3 times.
3 openstudio::filesystem::create_directories(tempDest);
1032
1033 3 std::vector<openstudio::path> createdFiles;
1034 try {
1035
1/1
✓ Branch 1 taken 3 times.
3 openstudio::UnzipFile uf(src);
1036
1/1
✓ Branch 1 taken 3 times.
3 createdFiles = uf.extractAllFiles(tempDest);
1037
0/2
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3 } catch (const std::exception& e) {
1038 ✗ LOG(Error, "Cannot unzip file: " << e.what());
1039 ✗ }
1040
1/1
✓ Branch 1 taken 3 times.
3 openstudio::filesystem::remove(src);
1041
1042 // search for component.xml or measure.xml file
1043 3 boost::optional<openstudio::path> xmlPath;
1044
1045
1/2
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
3 for (const auto& path : createdFiles) {
1046
2/3
✓ Branch 1 taken 3 times.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
6 if (path.filename() == toPath("component.xml")) {
1047
1/1
✓ Branch 1 taken 3 times.
3 componentType = "component";
1048 3 m_lastComponentDownload.reset();
1049
1/1
✓ Branch 1 taken 3 times.
3 xmlPath = path;
1050 3 break;
1051 ✗ } else if (path.filename() == toPath("measure.xml")) {
1052 ✗ componentType = "measure";
1053 ✗ m_lastMeasureDownload.reset();
1054 ✗ xmlPath = path;
1055 ✗ break;
1056 }
1057 }
1058
1059
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (xmlPath) {
1060 // cppcheck-suppress shadowVariable
1061
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
3 path src = xmlPath->parent_path();
1062
1/1
✓ Branch 1 taken 3 times.
3 path dest = src.parent_path();
1063
3/3
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
6 openstudio::filesystem::remove(dest / toPath("DISCLAIMER.txt"));
1064
3/3
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
6 openstudio::filesystem::remove(dest / toPath("README.txt"));
1065
3/3
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
6 openstudio::filesystem::remove(dest / toPath("output.xml"));
1066
1/1
✓ Branch 1 taken 3 times.
3 copyDirectory(src, dest);
1067
1/1
✓ Branch 1 taken 3 times.
3 removeDirectory(src);
1068
1069
2/3
✓ Branch 1 taken 3 times.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
3 if (componentType == "component") {
1070
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
6 path componentXmlPath = dest / toPath("component.xml");
1071 // open the component to figure out uid and vid
1072
3/3
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 8 taken 3 times.
3 BCLComponent component(toString(componentXmlPath.parent_path()));
1073
1/1
✓ Branch 1 taken 3 times.
3 std::string uid = component.uid();
1074
1/1
✓ Branch 1 taken 3 times.
3 std::string versionId = component.versionId();
1075
1076 // check if component has proper uid and vid
1077
3/6
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
3 if (!uid.empty() && !versionId.empty()) {
1078
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
6 dest = LocalBCL::instance().libraryPath() / uid / versionId;
1079
1080
1/1
✓ Branch 1 taken 3 times.
3 removeDirectory(dest);
1081
3/4
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
3 if (copyDirectory(componentXmlPath.parent_path(), dest)) {
1082 // Add to LocalBCL
1083
3/3
✓ Branch 1 taken 3 times.
✓ Branch 5 taken 3 times.
✓ Branch 8 taken 3 times.
3 m_lastComponentDownload = BCLComponent(toString(dest));
1084
3/3
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
3 LocalBCL::instance().addComponent(*m_lastComponentDownload);
1085 }
1086 }
1087
0/3
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
3 } else if (componentType == "measure") {
1088 ✗ path measureXmlPath = dest / toPath("measure.xml");
1089 // open the measure to figure out uid and vid
1090 ✗ boost::optional<BCLMeasure> measure;
1091 try {
1092 ✗ measure = BCLMeasure(measureXmlPath.parent_path());
1093
1094 ✗ std::string uid = measure->uid();
1095 ✗ std::string versionId = measure->versionId();
1096
1097 // check if component has proper uid and vid
1098 ✗ if (!uid.empty() && !versionId.empty()) {
1099 ✗ dest = LocalBCL::instance().libraryPath() / uid / versionId;
1100 ✗ removeDirectory(dest);
1101 ✗ if (copyDirectory(measureXmlPath.parent_path(), dest)) {
1102 // Add to LocalBCL
1103 ✗ m_lastMeasureDownload = BCLMeasure(dest);
1104 ✗ LocalBCL::instance().addMeasure(*m_lastMeasureDownload);
1105 }
1106 }
1107 ✗ } catch (const std::exception&) {
1108 ✗ LOG(Error, "Unable to create measure from download: " + toString(measureXmlPath.parent_path()));
1109 ✗ }
1110 ✗ }
1111 3 } else {
1112 ✗ LOG(Error, "No component.xml or measure.xml file found in downloaded contents");
1113 }
1114
1115 // delete the temp unzip directory
1116
1/1
✓ Branch 1 taken 3 times.
3 removeDirectory(tempDest);
1117
1118
2/3
✓ Branch 1 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
3 if (componentType == "measure") {
1119 ✗ this->measureDownloaded.nano_emit(m_downloadUid, m_lastMeasureDownload);
1120 } else {
1121
1/1
✓ Branch 1 taken 3 times.
3 this->componentDownloaded.nano_emit(m_downloadUid, m_lastComponentDownload);
1122 }
1123 3 }
1124
1125 ✗ int RemoteBCL::setResultsPerQuery(const int numResults) {
1126 ✗ m_numResultsPerQuery = numResults <= 0 ? 10 : numResults > 100 ? 100 : numResults;
1127 ✗ return m_numResultsPerQuery;
1128 }
1129
1130 20 void RemoteBCL::setLastTotalResults(const int lastTotalResults) {
1131 20 m_lastTotalResults = lastTotalResults;
1132 20 }
1133
1134 } // namespace openstudio
1135