-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathecmfSync.apex
4387 lines (3918 loc) · 256 KB
/
ecmfSync.apex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
global class ecmfSync implements Database.Batchable<String>, Database.AllowsCallouts, Database.Stateful {
global List<String> projectIdList = new List<String>();
global String authorization = '';
private List<string> ekotropeStages = new List<string>();
global List<Object> newResults = new List<Object>();
global Map<String, String> existingViridiantMfProjectsMap = new Map<String, String>();
global Map<String, List<String>> existingViridiantMFProjectsMapSfID = new Map<String, List<String>>();
global Map<String, String> ekoIdMap = new Map<String, String>();
private final List<string> codesToCheck = new List<string>();
private List<string> buildingsToCheck = new List<string>();
private string baselineBuilding = '';
private string referenceBuilding = '';
private string designBuilding = '';
private string dataPrefix = '';
global List<Project__c> ekotropeIdList = new List<Project__c>();
global List<Building_Specifications__c> buildingSpecList = new List<Building_Specifications__c>();
global List<Unit_Takeoff__c> unitTakeoffList = new List<Unit_Takeoff__c>();
global List<HERS_Data__c> hersDataList = new List<HERS_Data__c>();
global Iterable<String> start(Database.BatchableContext bc){
//just add records where they do not exist and update records where they do
//if ekotrope_self is blank, then add
//if ekotrope_self is filled, check to see if update is necessary
// Now we need to get the MF ratings that have specified EkoIds
for(Unit_Takeoff__c existingMfProject : [Select Ekotrope_Model_ID__c, Ekotrope_selfOrPlanLastSavedAt__c, ID, Name
FROM Unit_Takeoff__c
where Ekotrope_Model_ID__c != null and Ekotrope_selfOrPlanLastSavedAt__c = null])
{
existingViridiantMfProjectsMap.put(existingMfProject.Id, 'add-record-details');
system.debug(existingMfProject.id);
}
for(Unit_Takeoff__c existingMfProject : [
Select Ekotrope_Model_ID__c, Ekotrope_selfOrPlanLastSavedAt__c, ID, Name
FROM Unit_Takeoff__c
where Ekotrope_Model_ID__c != null and Ekotrope_selfOrPlanLastSavedAt__c != null])
{
List<String> updateStatusList = new List<String>();
system.debug(existingMfProject.id);
updateStatusList.add(existingMfProject.Ekotrope_Model_ID__c);
updateStatusList.add(existingMfProject.Id);
updateStatusList.add(existingMfProject.Ekotrope_selfOrPlanLastSavedAt__c);
existingViridiantMFProjectsMapSfID.put(existingMFProject.Id, updateStatusList);
}
system.debug(existingViridiantMFProjectsMapSfID);
for(string ekoStage : ekotropeStages){
if(test.isRunningTest()){Test.setMock(HttpCalloutMock.class, new ekotropeMockHttpProjListCallout());}
HttpResponse projectListResponse = ekotropeSync.getProjectList(authorization, ekoStage);
if(projectListResponse.getStatusCode() == 200){
String newProjectList = String.valueOf(projectListResponse.getBody());
if(projectListResponse.getBody() != ''){
newResults = (List<Object>)JSON.deserializeUntyped(newProjectList);
//iterate over all projects in ekotrope and add them to map
for(Object project : newResults){
Map<String, Object> projectData = (Map<String, Object>)project;
//load ekotrope results into a map
ekoIdMap.put(String.valueOf(projectData.get('id')),String.valueOf(projectData.get('selfOrPlanLastSavedAt')));
}
}
}
}
//iterate over existingViridiantMFProjectsMapSfID
//query the ekoIdMap and see if any selfOrPlanLastSavedAt are different
//to determine if any projects need updated
system.debug(existingViridiantMfProjectsMap.keySet());
system.debug('iterating over all of the existingViridiantMFProjectsMapSfIDs. This is may add a duplicate');
for(string salesforceID : existingViridiantMFProjectsMapSfID.keySet()){
system.debug(salesforceID);
//get the eko Id for this project
String ekoId = existingViridiantMFProjectsMapSfID.get(salesforceID)[0];
//get the lastplansaved date for this proejct
String saveDate = existingViridiantMFProjectsMapSfID.get(salesforceID)[2];
//get ekotropes' lastplansaved date
String ekoSaveDate = ekoIdMap.get(ekoId);
if(saveDate != ekoSaveDate){
existingViridiantMfProjectsMap.put(salesforceID, 'update-record');
}
}
system.debug(existingViridiantMfProjectsMap.keySet());
projectIdList.addAll(existingViridiantMfProjectsMap.keySet());
// List of salesforce ids which need to be updated or added to salesforce
// these are all ecmf projects so just the worst case model is added
// they do not count towards
system.debug(projectIdList);
return projectIdList;
}
global void execute(Database.BatchableContext bc, List<String> projectsToUpdate){
List<Unit_Takeoff__c> addUnits = new List<Unit_Takeoff__c>();
List<Project__c> addProjects = new List<Project__c>();
List<HERS_Data__C> addHersData = new List<HERS_Data__c>();
List<HERS_Data__C> upsertHersData = new List<HERS_Data__c>();
//Use the salesforce ids to get update or add the necessary energy model data
//
//iterate through ids
//each id review the map to determine if they are to to updated or added
//
//construct the HERS record, unit record, building record, and project for each
//upsert the records
List<Log__c> errorLogs = new List<Log__c>();
String raterId = null;
String RFI_Rater = null;
String project_status = null;
Map<String, String> raterMap = new Map<String, String>();
for(Contact existingContact : [
Select RTIN_RFIN__c, name, id
FROM contact
WHERE RTIN_RFIN__c != null ])
{raterMap.put(existingContact.RTIN_RFIN__c, existingContact.id);}
list<RecordType> recordTypes = [select id, name from RecordType where name like '%Multifamily%'];
id multiFamRecordId;
if(recordTypes.size()>0){
multiFamRecordId = recordTypes.get(0).id;
}
system.debug('iterate over projectsToUpdate:');
system.debug(projectsToUpdate);
for(String projectId:projectsToUpdate){
//we update the data or create the new records
system.debug(projectId);
Unit_Takeoff__c unitTakeoff;
unitTakeoff = [SELECT Ekotrope_Model_ID__c, Ekotrope_selfOrPlanLastSavedAt__c,
ID, Name, Building_Specification__r.id
FROM Unit_Takeoff__c WHERE Id = :projectId];
Building_Specifications__c buildingSpec;
string buildId = unitTakeoff.Building_Specification__r.id;
buildingSpec = [Select Id, Name, Project__r.id
from Building_Specifications__C
where id = :buildId];
Project__c project;
string projId = buildingSpec.Project__r.id;
project = [Select Id, Name
from Project__c
where id = :projId];
String ekoProjectId = unitTakeoff.Ekotrope_Model_ID__c;
//system.debug(ekoProjectId);
// first get all of the necessary information from ekotrope
if (Test.isRunningTest()) {Test.setMock(HttpCalloutMock.class, new ekotropeMockHttpProjectCallout() ); }
HttpResponse projectResponse = ekotropeSync.getProject(authorization, ekoProjectId);
//system.debug(projectResponse.getBody());
if(projectResponse.getStatusCode() == 418){
system.debug('Project has status code 418: '+projectId);
//system.debug(projectResponse.getBody());
Log__c errorLog = ekotropeSync.constructErrorLog('getProject','getProject', projectResponse, ekoProjectId, projectResponse.getBody());
errorLogs.add(errorLog);
} else if(projectResponse.getStatusCode() == 200){
String newProject = String.valueOf(projectResponse.getBody());
projectJSON2Apex.aProjectJSON2Apex qProject = projectJSON2Apex.parse(newProject);
//if this is a test method we need to set the appropriate mock class
if (Test.isRunningTest()) {Test.setMock(HttpCalloutMock.class, new ekotropeMockHttpDesignCallout() ); }
//system.debug(qProject.masterPlanId);
HttpResponse planResponse = ekotropeSync.getHousePlan(authorization, qProject.masterPlanId);
//system.debug(planResponse.getBody());
//if this is a test method we need to set the appropriate mock class
if (Test.isRunningTest()) {Test.setMock(HttpCalloutMock.class, new ekotropeMockHttpAnalysisCallout() ); }
HttpResponse analysisResponse = ekotropeSync.getHousePlanAnalysis(authorization, qProject.masterPlanId, 'EkotropeAsModeled', codesToCheck);
//system.debug(analysisResponse.getBody());
//if this is a test method we need to set the appropriate mock class
if (Test.isRunningTest()) {Test.setMock(HttpCalloutMock.class, new ekotropeMockHttpAnalysisCallout() ); }
HttpResponse ReferenceAnalysisResponse = ekotropeSync.getHousePlanAnalysis(authorization, qProject.masterPlanId, 'HERSReference', codesToCheck);
//system.debug(ReferenceAnalysisResponse.getBody());
//if this is a test method we need to set the appropriate mock class
// add to getHousePlanAnalysis if building type != 'EkotropeAsModeled' do not include the building type
if (Test.isRunningTest()) {Test.setMock(HttpCalloutMock.class, new ekotropeMockHttpAnalysisCallout() ); }
HttpResponse doeAnalysisResponse = ekotropeSync.getHousePlanAnalysis(authorization, qProject.masterPlanId, 'DOEZeroEnergyReadyTarget', codesToCheck);
//system.debug(DesignanalysisResponse.getBody());
// add to getHousePlanAnalysis if building type != 'EkotropeAsModeled' do not include the building type
if (Test.isRunningTest()) {Test.setMock(HttpCalloutMock.class, new ekotropeMockHttpAnalysisCallout() ); }
HttpResponse ieccAnalysisResponse = ekotropeSync.getHousePlanAnalysis(authorization, qProject.masterPlanId, 'IECC2015_5ACH50Reference', codesToCheck);
//system.debug(DesignanalysisResponse.getBody());
// add to getHousePlanAnalysis if building type != 'EkotropeAsModeled' do not include the building type
if (Test.isRunningTest()) {Test.setMock(HttpCalloutMock.class, new ekotropeMockHttpAnalysisCallout() ); }
HttpResponse virginiaAnalysisResponse = ekotropeSync.getHousePlanAnalysis(authorization, qProject.masterPlanId, 'Virginia2015Reference', codesToCheck);
//system.debug(virginiaAnalysisResponse.getBody());
// add to getHousePlanAnalysis if building type != 'EkotropeAsModeled' do not include the building type
if (Test.isRunningTest()) {Test.setMock(HttpCalloutMock.class, new ekotropeMockHttpAnalysisCallout() ); }
HttpResponse estar = ekotropeSync.getHousePlanAnalysis(authorization, qProject.masterPlanId, 'EnergyStarV3Reference', codesToCheck);
//system.debug(virginiaAnalysisResponse.getBody());
// add to getHousePlanAnalysis if building type != 'EkotropeAsModeled' do not include the building type
if (Test.isRunningTest()) {Test.setMock(HttpCalloutMock.class, new ekotropeMockHttpAnalysisCallout() ); }
HttpResponse estar31 = ekotropeSync.getHousePlanAnalysis(authorization, qProject.masterPlanId, 'EnergyStarV31Reference', codesToCheck);
//system.debug(virginiaAnalysisResponse.getBody());
// add to getHousePlanAnalysis if building type != 'EkotropeAsModeled' do not include the building type
if (Test.isRunningTest()) {Test.setMock(HttpCalloutMock.class, new ekotropeMockHttpAnalysisCallout() ); }
HttpResponse estarMF = ekotropeSync.getHousePlanAnalysis(authorization, qProject.masterPlanId, 'EnergyStarMFV11Reference', codesToCheck);
//system.debug(virginiaAnalysisResponse.getBody());
//Complete the response parsing and record creation only if all HTTP callouts were successful
if(estar.getStatusCode() == 200 && estar31.getStatusCode() == 200 && estarMF.getStatusCode() == 200 && planResponse.getStatusCode() == 200 && analysisResponse.getStatusCode() == 200 && referenceAnalysisResponse.getStatusCode() == 200 && doeAnalysisResponse.getStatusCode()==200 && ieccAnalysisResponse.getStatusCode() == 200 && virginiaAnalysisResponse.getStatusCode() == 200){
system.debug(Limits.getCpuTime());
String plan = String.valueOf(planResponse.getBody());
housePlanJSON2Apex qplan = housePlanJSON2Apex.parse(plan);
String AsIsAnalysis = String.valueOf(analysisResponse.getBody());
analysisJson2Apex.pAnalysisJson2Apex AsIsAnalysisResults = analysisJson2Apex.parse(AsIsAnalysis);
String ReferenceAnalysis = String.valueOf(ReferenceAnalysisResponse.getBody());
analysisJson2Apex.pAnalysisJson2Apex ReferencenalysisResults = analysisJson2Apex.parse(ReferenceAnalysis);
String doeAnalysis = String.valueOf(doeAnalysisResponse.getBody());
analysisJson2Apex.pAnalysisJson2Apex doeAnalysisResults = analysisJson2Apex.parse(doeAnalysis);
String ieccAnalysis = String.valueOf(ieccAnalysisResponse.getBody());
analysisJson2Apex.pAnalysisJson2Apex ieccAnalysisResults = analysisJson2Apex.parse(ieccAnalysis);
String virginiaAnalysis = String.valueOf(virginiaAnalysisResponse.getBody());
analysisJson2Apex.pAnalysisJson2Apex virginiaAnalysisResults = analysisJson2Apex.parse(virginiaAnalysis);
String estarAnalysis = String.valueOf(estar.getBody());
analysisJson2Apex.pAnalysisJson2Apex estarAnalysisResults = analysisJson2Apex.parse(estarAnalysis);
Sglobal class ekotropeSync implements Database.Batchable<String>, Database.AllowsCallouts, Database.Stateful {
global String newProjectsList = '';
private String ekotropeStatus = '';
private String updateStatus = '';
private List<string> ekotropeStages = new List<string>();
private boolean regularRun = True;
private string baselineBuilding = '';
private string referenceBuilding = '';
private string designBuilding = '';
private string doeBuilding = '';
private string iecc2015Building = '';
private string virginiaBuilding = '';
private string dataPrefix = '';
global String authorization = ''; //('Basic ' + EncodingUtil.base64Encode(headerValue));
global List<Project__c> ekotropeIdList = new List<Project__c>();
global List<String> projectIdList = new List<String>();
//global HttpResponse projectListResponse = new HttpResponse();
global List<Object> newResults = new List<Object>();
global Map<String, String> accountsMap = new Map<String, String>();
global Map<String, String> raterMap = new Map<String, String>();
global Map<String, String> existingViridiantProjectsMap = new Map<String, String>(); // Used for selfOrPlanLastSavedDate
global Map<String, String> existingViridiantMfProjectsMap = new Map<String, String>();
global Map<String, String> existingViridiantProjectsMapSfID = new Map<String, String>();// Used to store UnitTakeoff - Building Spec relationships
private final Map<String, String> globalProjectUpdateStatusList = new Map<String, String>();
global List<Log__c> errorLogs = new List<Log__c>();
private final List<string> codesToCheck = new List<string>();
private List<string> buildingsToCheck = new List<string>();
global Iterable<String> start(Database.BatchableContext bc){
//This gets SF and MF-Shadow that are already connected for the list to compare the Ekotrope Project List Results against
for(Unit_Takeoff__c existingProject : [Select Ekotrope_ID__c, Ekotrope_selfOrPlanLastSavedAt__c, ID, Name, Building_Specification__c
FROM Unit_Takeoff__c
WHERE Ekotrope_ID__c != null])
{
existingViridiantProjectsMap.put(existingProject.Ekotrope_ID__c, existingProject.Ekotrope_selfOrPlanLastSavedAt__c);
existingViridiantProjectsMapSfID.put(existingProject.Ekotrope_ID__c, existingProject.Building_Specification__c);
}
//iterate through the requested ekotrope stages and query the getProjectList API endpoint
//For each response, check to see if salesforce has the ekotrope project
//if it does, check to see if needs to be updated. if it doesn't, add the project to database
for(string ekoStage : ekotropeStages){
if(test.isRunningTest()){Test.setMock(HttpCalloutMock.class, new ekotropeMockHttpProjListCallout());}
//HttpResponse projectListResponse = getProjectListWithDate(authorization, ekoStage, '2020-01-01', '2020-06-27');
HttpResponse projectListResponse = getProjectList(authorization, ekoStage);
system.debug(projectListResponse.getStatusCode());
if(projectListResponse.getStatusCode() == 200){
String newProjectList = String.valueOf(projectListResponse.getBody());
if(projectListResponse.getBody() != ''){
newResults = (List<Object>)JSON.deserializeUntyped(newProjectList);
//iterate over the projects in Ekotrope
for(Object project : newResults){
Map<String, Object> projectData = (Map<String, Object>)project;
List<String> updateStatusList = new List<String>();
//Check to see if the project exists in existing Viridiant projects map (sf and mf-shadow)
if(existingViridiantProjectsMap.get(String.valueOf(projectData.get('id')))==null){
//ekotrope id does not exist in salesforce. so we add it to the add list
//we do not know if it is sf or mf. We add the mf projects to the shadow data structure
globalProjectUpdateStatusList.put(String.valueOf(projectData.get('id')), 'create-project');
} //If the id exists, then we check to see if it has changed
else if(projectData.get('selfOrPlanLastSavedAt') != existingViridiantProjectsMap.get(String.valueOf(projectData.get('id')))){
globalProjectUpdateStatusList.put(String.valueOf(projectData.get('id')), 'update-project');
}
}
} else{
system.debug('getProjectList returned a blank body');
if(!Test.isRunningTest()){
Log__c errorLog = constructErrorLog('getProjectList', 'getProjectList', projectListResponse, ekoStage, projectListResponse.getBody());
errorLogs.add(errorLog);
}
}
} else{
system.debug('getProjectList returned a non-200 status');
system.debug(projectListResponse.getBody());
if(!Test.isRunningTest()){
Log__c errorLog = constructErrorLog('getProjectList','getProjectList', projectListResponse, ekoStage, projectListResponse.getBody());
errorLogs.add(errorLog);
}
}
}
projectIdList.addAll(globalProjectUpdateStatusList.keySet());
system.debug(projectIdList);
system.debug('Number of Projects to update:: ' + projectIdList.size());
//insert errorLogs;
return projectIdList;
}
global void execute(Database.BatchableContext bc, List<String> projectsToUpdate){
system.debug('ekotropeSync.execute Start: '+Limits.getCpuTime());
map<string, boolean> ectaMap = new map<string, boolean>();
for(Contact existingContact : [
Select RTIN_RFIN__c, name, id, Earthcraft_TA__c
FROM contact
WHERE RTIN_RFIN__c != null ])
{
ectaMap.put(existingContact.RTIN_RFIN__c, existingContact.Earthcraft_TA__c);
}
List<Unit_Takeoff__c> addUnits = new List<Unit_Takeoff__c>();
List<Project__c> addProjects = new List<Project__c>();
List<HERS_Data__C> addHers = new List<HERS_Data__C>();
List<Building_Specifications__C> addBuildings = new List<Building_Specifications__C>();
List<Log__c> errorLogs = new List<Log__c>();
List<string> autoQaList = new List<string>();
//List<Inspections__c> autoQaRecordList = new List<Inspections__c>();
String raterId = null;
String RFI_Rater = null;
String project_status = null;
Project__c placeHolderProject = new Project__c();
list<RecordType> recordTypes = [select id, name from RecordType where name like '%Multifamily%'];
id multiFamRecordId;
if(recordTypes.size()>0){
multiFamRecordId = recordTypes.get(0).id;
}
list<Project__c> placeholderProjects = [Select Name, ID From Project__c
Where RESNET_Registry_ID__c = 'placeHolderProjectForAuto'
And recordTypeId = :multiFamRecordId
And Status_Multifamily__c = 'Pre-Review'];
if(placeholderProjects.size()>0){
placeHolderProject = placeholderProjects.get(0);
placeHolderProject.Name = 'Placeholder Project for Ekotrope Integration';
placeHolderProject.Status_Multifamily__c = 'Pre-Review';
placeHolderProject.RecordTypeId = multiFamRecordId;
//update placeHolderProject;
}else{
//placeHolderProject = new Project__c();
placeHolderProject.Resnet_Registry_ID__c = 'placeHolderProjectForAuto';
placeHolderProject.Name = 'Placeholder Project for Ekotrope Integration';
placeHolderProject.Status_Multifamily__c = 'Pre-Review';
placeHolderProject.RecordTypeId = multiFamRecordId;
addProjects.add(placeHolderProject);
//insert placeHolderProject;
}
string placeholderProjectId = placeHolderProject.id;
list<Building_Specifications__c> placeholderBuildingSpecs = [Select Name, ID From Building_Specifications__c
Where Project__c = :placeholderProjectId];
Building_Specifications__c placeholderBuildingSpec = new Building_Specifications__c();
if(placeholderBuildingSpecs.size()>0){
placeholderBuildingSpec = placeholderBuildingSpecs.get(0);
}else{
placeholderBuildingSpec.Name = 'Placeholder Project for Ekotrope Integration';
placeholderBuildingSpec.Project__c = placeholderProjectId;
addBuildings.add(placeholderBuildingSpec);
//insert placeholderBuildingSpec;
}
for(Contact existingContact : [
Select RTIN_RFIN__c, name, id
FROM contact
WHERE RTIN_RFIN__c != null ])
{raterMap.put(existingContact.RTIN_RFIN__c, existingContact.id);}
for(String projectId:projectsToUpdate){
system.debug(projectId);
// first get all of the necessary information from ekotrope
if (Test.isRunningTest()) {Test.setMock(HttpCalloutMock.class, new ekotropeMockHttpProjectCallout() );}
HttpResponse projectResponse = ekotropeSync.getProject(authorization, projectId);
system.debug(projectResponse.getStatusCode());
if(projectResponse.getStatusCode() == 418){
system.debug('Project has status code 418: '+projectId);
system.debug(projectResponse.getBody());
Log__c errorLog = ekotropeSync.constructErrorLog('getProject','getProject', projectResponse, projectId, projectResponse.getBody());
errorLogs.add(errorLog);
} else if(projectResponse.getStatusCode() == 200){
system.debug('projectResponse == 200');
String newProject = String.valueOf(projectResponse.getBody());
projectJSON2Apex.aProjectJSON2Apex qProject = projectJSON2Apex.parse(newProject);
system.debug(qProject.masterPlanId);
//if this is a test method we need to set the appropriate mock class
if (Test.isRunningTest()) {Test.setMock(HttpCalloutMock.class, new ekotropeMockHttpDesignCallout() ); }
HttpResponse planResponse = ekotropeSync.getHousePlan(authorization, qProject.masterPlanId);
system.debug(planResponse.getBody());
//if this is a test method we need to set the appropriate mock class
//get the energy data for the base model and to check all of the codes
//add to getHousePlanAnalysis to comment out the building type if == 'EkotropeAsModeled'
if (Test.isRunningTest()) {Test.setMock(HttpCalloutMock.class, new ekotropeMockHttpAnalysisCallout() ); }
HttpResponse analysisResponse = ekotropeSync.getHousePlanAnalysis(authorization, qProject.masterPlanId, 'EkotropeAsModeled', codesToCheck);
system.debug(analysisResponse.getBody());
//if this is a test method we need to set the appropriate mock class
// add to getHousePlanAnalysis if building type != 'EkotropeAsModeled' do not include the building type
if (Test.isRunningTest()) {Test.setMock(HttpCalloutMock.class, new ekotropeMockHttpAnalysisCallout() ); }
HttpResponse referenceAnalysisResponse = ekotropeSync.getHousePlanAnalysis(authorization, qProject.masterPlanId, 'HERSReference', codesToCheck);
//system.debug(ReferenceAnalysisResponse.getBody());
//if this is a test method we need to set the appropriate mock class
// add to getHousePlanAnalysis if building type != 'EkotropeAsModeled' do not include the building type
if (Test.isRunningTest()) {Test.setMock(HttpCalloutMock.class, new ekotropeMockHttpAnalysisCallout() ); }
HttpResponse doeAnalysisResponse = ekotropeSync.getHousePlanAnalysis(authorization, qProject.masterPlanId, 'DOEZeroEnergyReadyTarget', codesToCheck);
//system.debug(DesignanalysisResponse.getBody());
// add to getHousePlanAnalysis if building type != 'EkotropeAsModeled' do not include the building type
if (Test.isRunningTest()) {Test.setMock(HttpCalloutMock.class, new ekotropeMockHttpAnalysisCallout() ); }
HttpResponse ieccAnalysisResponse = ekotropeSync.getHousePlanAnalysis(authorization, qProject.masterPlanId, 'IECC2015_5ACH50Reference', codesToCheck);
//system.debug(DesignanalysisResponse.getBody());
// add to getHousePlanAnalysis if building type != 'EkotropeAsModeled' do not include the building type
if (Test.isRunningTest()) {Test.setMock(HttpCalloutMock.class, new ekotropeMockHttpAnalysisCallout() ); }
HttpResponse virginiaAnalysisResponse = ekotropeSync.getHousePlanAnalysis(authorization, qProject.masterPlanId, 'Virginia2015Reference', codesToCheck);
//system.debug(virginiaAnalysisResponse.getBody());
//
// add to getHousePlanAnalysis if building type != 'EkotropeAsModeled' do not include the building type
if (Test.isRunningTest()) {Test.setMock(HttpCalloutMock.class, new ekotropeMockHttpAnalysisCallout() ); }
HttpResponse estar = ekotropeSync.getHousePlanAnalysis(authorization, qProject.masterPlanId, 'EnergyStarV3Reference', codesToCheck);
//system.debug(virginiaAnalysisResponse.getBody());
// add to getHousePlanAnalysis if building type != 'EkotropeAsModeled' do not include the building type
if (Test.isRunningTest()) {Test.setMock(HttpCalloutMock.class, new ekotropeMockHttpAnalysisCallout() ); }
HttpResponse estar31 = ekotropeSync.getHousePlanAnalysis(authorization, qProject.masterPlanId, 'EnergyStarV31Reference', codesToCheck);
//system.debug(virginiaAnalysisResponse.getBody());
// add to getHousePlanAnalysis if building type != 'EkotropeAsModeled' do not include the building type
if (Test.isRunningTest()) {Test.setMock(HttpCalloutMock.class, new ekotropeMockHttpAnalysisCallout() ); }
HttpResponse estarMF = ekotropeSync.getHousePlanAnalysis(authorization, qProject.masterPlanId, 'EnergyStarMFV11Reference', codesToCheck);
//system.debug(virginiaAnalysisResponse.getBody());
//Complete the response parsing and record creation only if all HTTP callouts were successful
if(estar.getStatusCode() == 200 && estar31.getStatusCode() == 200 && estarMF.getStatusCode() == 200 && planResponse.getStatusCode() == 200 && analysisResponse.getStatusCode() == 200 && referenceAnalysisResponse.getStatusCode() == 200 && doeAnalysisResponse.getStatusCode()==200 && ieccAnalysisResponse.getStatusCode() == 200 && virginiaAnalysisResponse.getStatusCode() == 200){
String plan = String.valueOf(planResponse.getBody());
system.debug('before house plan parse');
system.debug(Limits.getCpuTime());
housePlanJSON2Apex qplan = housePlanJSON2Apex.parse(plan);
system.debug('after house plan parse');
system.debug(Limits.getCpuTime());
system.debug('before analysis parse');
system.debug(Limits.getCpuTime());
String AsIsAnalysis = String.valueOf(analysisResponse.getBody());
analysisJson2Apex.pAnalysisJson2Apex AsIsAnalysisResults = analysisJson2Apex.parse(AsIsAnalysis);
String ReferenceAnalysis = String.valueOf(ReferenceAnalysisResponse.getBody());
analysisJson2Apex.pAnalysisJson2Apex ReferencenalysisResults = analysisJson2Apex.parse(ReferenceAnalysis);
String doeAnalysis = String.valueOf(doeAnalysisResponse.getBody());
analysisJson2Apex.pAnalysisJson2Apex doeAnalysisResults = analysisJson2Apex.parse(doeAnalysis);
String ieccAnalysis = String.valueOf(ieccAnalysisResponse.getBody());
analysisJson2Apex.pAnalysisJson2Apex ieccAnalysisResults = analysisJson2Apex.parse(ieccAnalysis);
String virginiaAnalysis = String.valueOf(virginiaAnalysisResponse.getBody());
analysisJson2Apex.pAnalysisJson2Apex virginiaAnalysisResults = analysisJson2Apex.parse(virginiaAnalysis);
String estarAnalysis = String.valueOf(estar.getBody());
analysisJson2Apex.pAnalysisJson2Apex estarAnalysisResults = analysisJson2Apex.parse(estarAnalysis);
String estar31Analysis = String.valueOf(estar31.getBody());
analysisJson2Apex.pAnalysisJson2Apex estar31AnalysisResults = analysisJson2Apex.parse(estar31Analysis);
String estarMFAnalysis = String.valueOf(estarMF.getBody());
analysisJson2Apex.pAnalysisJson2Apex estarMFAnalysisResults = analysisJson2Apex.parse(estarMFAnalysis);
system.debug('after analysis parse');
system.debug(Limits.getCpuTime());
if(globalProjectUpdateStatusList.get(projectId) == 'update-project'){
/*Notes:
* - Ekotrope ID is in Salesforce on the Unit Takeoff Record
* - Update the Project__c, Building_Specification__c, Unit_Takeoff__c, HERS_Data__c
* - Project should not pass through QA Selection
* - Project should be checked for Matching
*/
string buildingSpecId = existingViridiantProjectsMapSfId.get(qProject.Id);
Unit_Takeoff__c newUnitTakeoff = constructTakeoffRecord(qProject, qplan, AsIsAnalysisResults, buildingSpecId);
HERS_Data__c newHERSData = constructEnergyDataRecord(qProject, qplan, AsIsAnalysisResults,ReferencenalysisResults, doeAnalysisResults,ieccAnalysisResults,virginiaAnalysisResults, 'HERS');
Project__c updateProjectData = constructProjectRecord(qProject, AsIsAnalysisResults, raterId);
Unit_Takeoff__c placeholderUnit = new Unit_Takeoff__c(
Ekotrope_ID__c = qProject.Id
);
newUnitTakeoff.Ekotrope_ID__c = qProject.Id;
newUnitTakeoff.Building_Specification__c = placeholderBuildingSpec.Id;
newHERSData.Ekotrope_Plan_ID__c = qProject.id;
newHERSData.HERS_Project__r = placeholderUnit;
newHERSData.Energy_Star_V3_Target_HERS__c = string.valueOf(estarAnalysisResults.hersScore);
newHERSData.Energy_Star_V3_1_Target_HERS__c = string.valueOf(estar31AnalysisResults.hersScore);
newHERSData.Energy_Star_MF_1_Target_HERS__c = string.valueOf(estarMFAnalysisResults.hersScore);
addUnits.add(newUnitTakeoff);
addHers.add(newHERSData);
} else{
/*
* project is not in Ekotrope as Unit Takeoff.
* Which means it should be processed through the
* Determine QA - QA_Status = 'Un-determined'
* If the project has an ECTA than do matching - Sync_Status = 'new',
* if not do not do matching - Sync_Status = 'create'
*/
Unit_Takeoff__c newUnitTakeoff = constructTakeoffRecord(qProject, qplan, AsIsAnalysisResults, placeholderBuildingSpec.Id);
newUnitTakeoff.Building_Specification__c = placeholderBuildingSpec.id;
HERS_Data__C newHERSData = constructEnergyDataRecord(qProject, qplan, AsIsAnalysisResults,ReferencenalysisResults, doeAnalysisResults,ieccAnalysisResults,virginiaAnalysisResults, 'HERS');
Unit_Takeoff__c placeholderUnit = new Unit_Takeoff__c(
Ekotrope_ID__c = qProject.Id
);
newUnitTakeoff.QA_Status__c = 'Un-determined';
system.debug(qproject.Id);
newHERSData.HERS_Project__r = placeholderUnit;
newHERSData.Ekotrope_Plan_ID__c = qProject.id;
newUnitTakeoff.Ekotrope_ID__c = qProject.Id;
newUnitTakeoff.Sync_Status__c = 'new';
if(ectaMap.get(newUnitTakeoff.HERS_Rater__c)==null){
newUnitTakeoff.Sync_Status__c = 'create';
newUnitTakeoff.QA_Status__c = 'On Hold';
}else{
if(ectaMap.get(newUnitTakeoff.HERS_Rater__c) == false){
newUnitTakeoff.Sync_Status__c = 'create';
}
}
addUnits.add(newUnitTakeoff);
addHers.add(newHERSData);
}
} // not all callouts were successfull
else{
system.debug('Not all http callouts were successfull. Project == 200, others ?');
if(planResponse.getStatusCode() != 200){
system.debug('planResponse code:');
system.debug(planResponse.getStatusCode());
Log__c errorLog = ekotropeSync.constructErrorLog('getHousePlan','getHousePlan', planResponse, projectId, planResponse.getBody());
errorLogs.add(errorLog);
}
if(analysisResponse.getStatusCode() != 200){
system.debug('analysisResponse code:');
system.debug(analysisResponse.getStatusCode());
Log__c errorLog = EkotropeSync.constructErrorLog('getHousePlanAnalysis - EkotropeAsModeled','getHousePlanAnalysis', analysisResponse, projectId, analysisResponse.getBody());
errorLogs.add(errorLog);
}
if(ReferenceAnalysisResponse.getStatusCode() != 200){
system.debug('ReferenceAnalysisResponse code:');
system.debug(ReferenceAnalysisResponse.getStatusCode());
Log__c errorLog = EkotropeSync.constructErrorLog('getHousePlanAnalysis - HERSReference','getHousePlanAnalysis', ReferenceAnalysisResponse, projectId, ReferenceAnalysisResponse.getBody());
errorLogs.add(errorLog);
}
if(doeAnalysisResponse.getStatusCode() != 200){
system.debug('doeAnalysisResponse code:');
system.debug(doeAnalysisResponse.getStatusCode());
Log__c errorLog = EkotropeSync.constructErrorLog('getHousePlanAnalysis - DOE','getHousePlanAnalysis', doeAnalysisResponse, projectId, doeAnalysisResponse.getBody());
errorLogs.add(errorLog);
}
if(ieccAnalysisResponse.getStatusCode() != 200){
system.debug('ieccAnalysisResponse code:');
system.debug(ieccAnalysisResponse.getStatusCode());
Log__c errorLog = EkotropeSync.constructErrorLog('getHousePlanAnalysis - IECC','getHousePlanAnalysis', ieccAnalysisResponse, projectId, ieccAnalysisResponse.getBody());
errorLogs.add(errorLog);
}
if(virginiaAnalysisResponse.getStatusCode() != 200){
system.debug('virginiaAnalysisResponse code:');
system.debug(virginiaAnalysisResponse.getStatusCode());
Log__c errorLog = EkotropeSync.constructErrorLog('getHousePlanAnalysis - Virginia','getHousePlanAnalysis', virginiaAnalysisResponse, projectId, virginiaAnalysisResponse.getBody());
errorLogs.add(errorLog);
}
}
} // projectResponse was not statusCode == 200
else{
Log__c errorLog = EkotropeSync.constructErrorLog('getProject','getProject', projectResponse, projectId, projectResponse.getBody());
errorLogs.add(errorLog);
system.debug(projectId);
system.debug(projectResponse.getBody());
}
}
system.debug(addHers);
upsert addUnits Unit_Takeoff__c.Fields.Ekotrope_ID__c;
upsert addProjects;
upsert addHers HERS_Data__c.Fields.Ekotrope_Plan_ID__c;
addProjects.clear();
}
global void finish(Database.BatchableContext bc){
batchMatching matchProjects = new batchMatching();
//will need to make different energy data records
// one for HERS data or we put everything HERS (3) plus the three additional records.
matchProjects.setSyncStatus('new');
Id newProjectBatchId = Database.executeBatch(matchProjects,300);
determineQa();
ekotropeUpload uploadProjects = new ekotropeUpload();
uploadProjects.setAuthorization(authorization);
Id uploadProjectBatchId = Database.executeBatch(uploadProjects, 2);
insert errorLogs;
}
public static Project__c constructProjectRecord(projectJSON2Apex.aProjectJSON2Apex aProject, analysisJson2Apex.pAnalysisJson2Apex bAnalysis, string cRater){
//MF I don't know what to do
projectJSON2APex.aProjectJSON2Apex a = aProject;
analysisJson2Apex.pAnalysisJson2Apex b = bAnalysis;
string rater = cRater;
string ekoId = a.id;
string street = a.location.streetAddress;
string city = a.location.city;
string state = a.location.state;
string zip = a.location.zip;
string registryId = a.hersRatingDetails.registryId;
string index = string.valueOf(b.hersScore);
Project__c projectRecord = new Project__c(
SF_Ekotrope_ID__c = ekoId,
//Name= '',
Street_Address__c= street,
City__c = city,
State__c = state,
zip_code__c = zip,
RESNET_Registry_ID__c = zip,
Rater__c = rater,
// Registration_Date__c ='',
// Rating_Date__c = '',
HERS_Index__c = index
);
return projectRecord;
}
public static Unit_Takeoff__c constructTakeoffRecord(projectJSON2Apex.aProjectJSON2Apex aProject, housePlanJSON2Apex rplan, analysisJson2Apex.pAnalysisJson2Apex analysis, string buildingSpecId){
string Water_Heating, Water_Heating_Capacity, Water_Heating_Efficiency, Hot_Water, Mechanical_Ventilation;
string Ventilation_CFM, Ventilation_Watts;
string floorRvalue, predominantFloorId, predomFloorName;
string foundationType, foundationRValue, predomFoundationName;
boolean energyStar, estarV31, estarMFV1;
string Solar_Hot_Water;
string predomWallDetails, predomWallR, predomWallId, predomWallName, predomWallSpacing, predomWallDepth;
string predomCeilingR, predominantCeilingId, predomCeilingName;
string predomDoorR, predominantDoorId, predomDoorName, lastSaved;
string windowDetail, predomWindowU, predominantWindowId, predomWindowName, predomWindowSHGC;
string selfOrPlan, fuel;
analysisJson2Apex.pAnalysisJson2Apex hersAnalysis = analysis;
housePlanJSON2Apex thisHousePlan = rplan;
projectJSON2Apex.aProjectJSON2Apex thisProject = aProject;
//planJson2Apex.aPlanJson2Apex thisHousePlan = rplan;
selfOrPlan = thisProject.selfOrPlanLastSavedAt;
try{
fuel = thisHousePlan.mechanicals.summary.dominantHeatingEquipmentType.fuel;
} catch(exception e){
fuel = '';
}
Date RESNET_Registration_Date = Date.newInstance(1999,1,1);
if (thisProject.hersRatingDetails.ratingDate != null){
RESNET_Registration_Date = Date.newInstance(
Integer.valueOf(String.valueOf(thisProject.hersRatingDetails.ratingDate).substring(0,4)),
Integer.valueOf(String.valueOf(thisProject.hersRatingDetails.ratingDate).substring(5,7)),
Integer.valueOf(String.valueOf(thisProject.hersRatingDetails.ratingDate).substring(8,10)));
}else{
RESNET_Registration_Date = null;
}
string houseType = '';
if(thisHousePlan.Details.residenceType != null){
string residenceTypeString = thisHousePlan.Details.residenceType;
if(residenceTypeString == 'SingleFamilyHouse' | residenceTypeString == 'TownhouseEndUnit' | residenceTypeString == 'TownhouseInsideUnit' | residenceTypeString == 'DuplexSingleUnit' | residenceTypeString == 'DuplexWholeBuilding'){
houseType = 'singlefamily';
}
else{
houseType = 'multifamily';
}
}
string levenString = normalizeLechString(thisProject.name, thisProject.location.StreetAddress, thisProject.location.City , thisProject.location.state);
integer count2 = 0;
string Heating_Sys_1,Heating_Fuel,Heating_Capacity,HSPF_AFUE_COP,Cooling_Sys_1;
string Cooling_Capacity,SEER_EER, Ductless, Ducts_100_w_in_conditioned_space;
string Total_Duct_Leakage, LtO, Area_Served;
string Heating_Sys_4, Heating_Fuel_Sys_4, Heating_Capacity_Sys_4, HSPF_AFUE_COP_Sys_4;
string Cooling_Sys_4, Cooling_Capacity_Sys_4, SEER_EER_Sys_4;
boolean Ductless_Sys_4;
Ductless_Sys_4 = false;
boolean Ducts_100_w_in_conditioned_space_Sys_4;
Ducts_100_w_in_conditioned_space_Sys_4 = false;
string Total_Duct_Leakage_Sys_4, LtO_Sys_4, Area_Served_Sys_4;
string Heating_Sys_3, Heating_Fuel_Sys_3, Heating_Capacity_Sys_3, HSPF_AFUE_COP_Sys_3;
string Cooling_Sys_3, Cooling_Capacity_Sys_3, SEER_EER_Sys_3;
boolean Ductless_Sys_3;
Ductless_Sys_3 = false;
boolean Ducts_100_w_in_conditioned_space_Sys_3;
Ducts_100_w_in_conditioned_space_Sys_3 = false;
string Total_Duct_Leakage_Sys_3, LtO_Sys_3, Area_Served_Sys_3;
string Heating_Sys_2, Heating_Fuel_Sys_2, Heating_Capacity_Sys_2, HSPF_AFUE_COP_Sys_2;
string Cooling_Sys_2, Cooling_Capacity_Sys_2, SEER_EER_Sys_2;
boolean Ductless_Sys_2;
boolean Ducts_100_w_in_conditioned_space_Sys_2;
Ducts_100_w_in_conditioned_space_Sys_2 = false;
string Total_Duct_Leakage_Sys_2, LtO_Sys_2, Area_Served_Sys_2;
integer heatCounter = 0;
integer coolCounter = 0;
Ductless_Sys_2 = false;
string Thermostat = string.valueOf(thisHousePlan.Details.programmableThermostat);
integer i2 = thisHousePlan.mechanicals.equipment.size();
while (count2 < i2){
//system.debug(count2);
//system.debug(thisHousePlan.mechanicals.equipment[count2].equipmentType);
if (Test.isRunningTest()) {
if(coolCounter == 4){
coolCounter =0;
}
if(heatCounter == 4){
heatCounter = 0;
}
}
If (thisHousePlan.mechanicals.equipment[count2].equipmentType == 'AIR_CONDITIONER'){
if(thisHousePlan.mechanicals.equipment[count2].cooling.percentLoad > 0){
// system.debug('ac system');
if(coolCounter == 0){
coolCounter = coolCounter + 1;
Cooling_Sys_1 = 'Air Conditioner';
//Cooling_Capacity = '';
SEER_EER = string.valueOf(thisHousePlan.mechanicals.equipment[count2].cooling.efficiency) + ' '+
string.valueOf(thisHousePlan.mechanicals.equipment[count2].cooling.efficiencyType) ;
SEER_EER = SEER_EER.abbreviate(25);
}
if(coolCounter == 1){
coolCounter = coolCounter + 1;
Cooling_Sys_2 = 'Air Conditioner';
//Cooling_Capacity = '';
SEER_EER_Sys_2 = string.valueOf(thisHousePlan.mechanicals.equipment[count2].cooling.efficiency) + ' '+
string.valueOf(thisHousePlan.mechanicals.equipment[count2].cooling.efficiencyType) ;
SEER_EER_Sys_2 = SEER_EER_Sys_2.abbreviate(25);
}
if(coolCounter == 2){
coolCounter = coolCounter + 1;
Cooling_Sys_3 = 'Air Conditioner';
//Cooling_Capacity = '';
SEER_EER_Sys_3 = string.valueOf(thisHousePlan.mechanicals.equipment[count2].cooling.efficiency) + ' ' +
string.valueOf(thisHousePlan.mechanicals.equipment[count2].cooling.efficiencyType) ;
SEER_EER_Sys_3= SEER_EER_Sys_3.abbreviate(25);
}
if(coolCounter == 2){
coolCounter = coolCounter + 1;
Cooling_Sys_3 = 'Air Conditioner';
//Cooling_Capacity = '';
SEER_EER_Sys_4 = string.valueOf(thisHousePlan.mechanicals.equipment[count2].cooling.efficiency) + ' '+
string.valueOf(thisHousePlan.mechanicals.equipment[count2].cooling.efficiencyType) ;
SEER_EER_Sys_4 = SEER_EER_Sys_4.abbreviate(25);
}
}
}
If (thisHousePlan.mechanicals.equipment[count2].equipmentType == 'AIR_SOURCE_HEAT_PUMP'){
if(thisHousePlan.mechanicals.equipment[count2].cooling.percentLoad > 0){
// system.debug('ac system');
if(coolCounter == 0){
Cooling_Sys_1 = 'AIR_SOURCE_HEAT_PUMP';
//Cooling_Capacity = '';
SEER_EER = string.valueOf(thisHousePlan.mechanicals.equipment[count2].cooling.efficiency) + ' '+
string.valueOf(thisHousePlan.mechanicals.equipment[count2].cooling.efficiencyType) ;
SEER_EER = SEER_EER.abbreviate(25);
}
if(coolCounter == 1){
Cooling_Sys_2 = 'AIR_SOURCE_HEAT_PUMP';
//Cooling_Capacity = '';
SEER_EER_Sys_2 = string.valueOf(thisHousePlan.mechanicals.equipment[count2].cooling.efficiency) + ' '+
string.valueOf(thisHousePlan.mechanicals.equipment[count2].cooling.efficiencyType) ;
SEER_EER_Sys_2 = SEER_EER_Sys_2.abbreviate(25);
}
if(coolCounter == 2){
//coolCounter = coolCounter + 1;
Cooling_Sys_3 = 'AIR_SOURCE_HEAT_PUMP';
//Cooling_Capacity = '';
SEER_EER_Sys_3 = string.valueOf(thisHousePlan.mechanicals.equipment[count2].cooling.efficiency) + ' ' +
string.valueOf(thisHousePlan.mechanicals.equipment[count2].cooling.efficiencyType) ;
SEER_EER_Sys_3 = SEER_EER_Sys_3.abbreviate(25);
}
if(coolCounter == 2){
// coolCounter = coolCounter + 1;
Cooling_Sys_4 = 'AIR_SOURCE_HEAT_PUMP';
//Cooling_Capacity = '';
SEER_EER_Sys_4 = string.valueOf(thisHousePlan.mechanicals.equipment[count2].cooling.efficiency) + ' '+
string.valueOf(thisHousePlan.mechanicals.equipment[count2].cooling.efficiencyType) ;
SEER_EER_Sys_4 = SEER_EER_Sys_4.abbreviate(25);
}
coolCounter = coolCounter + 1;
}
if(thisHousePlan.mechanicals.equipment[count2].heating.percentLoad > 0){
system.debug('heat system');
if(heatCounter == 0){
Heating_Sys_1 = 'AIR_SOURCE_HEAT_PUMP';
//Cooling_Capacity = '';
//Heating_Fuel
HSPF_AFUE_COP = string.valueOf(thisHousePlan.mechanicals.equipment[count2].heating.efficiency) + ' '+
string.valueOf(thisHousePlan.mechanicals.equipment[count2].heating.efficiencyType) ;
HSPF_AFUE_COP = HSPF_AFUE_COP.abbreviate(25);
}
if(heatCounter == 1){
//heatCounter = heatCounter + 1;
Heating_Sys_2 = 'AIR_SOURCE_HEAT_PUMP';
//Cooling_Capacity = '';
//Heating_Fuel
HSPF_AFUE_COP_Sys_2 = string.valueOf(thisHousePlan.mechanicals.equipment[count2].heating.efficiency) + ' '+
string.valueOf(thisHousePlan.mechanicals.equipment[count2].heating.efficiencyType) ;
HSPF_AFUE_COP_Sys_2 = HSPF_AFUE_COP_Sys_2.abbreviate(25);
}
if(heatCounter == 2){
//heatCounter = heatCounter + 1;
Heating_Sys_3 = 'AIR_SOURCE_HEAT_PUMP';
//Cooling_Capacity = '';
//Heating_Fuel
HSPF_AFUE_COP_Sys_3 = string.valueOf(thisHousePlan.mechanicals.equipment[count2].heating.efficiency) + ' '+
string.valueOf(thisHousePlan.mechanicals.equipment[count2].heating.efficiencyType) ;
HSPF_AFUE_COP_Sys_3 = HSPF_AFUE_COP_Sys_3.abbreviate(25);
}
if(heatCounter == 3){
//heatCounter = heatCounter + 1;
Heating_Sys_4 = 'AIR_SOURCE_HEAT_PUMP';
//Cooling_Capacity = '';
//Heating_Fuel
HSPF_AFUE_COP_Sys_4 = string.valueOf(thisHousePlan.mechanicals.equipment[count2].heating.efficiency) + ' '+
string.valueOf(thisHousePlan.mechanicals.equipment[count2].heating.efficiencyType) ;
HSPF_AFUE_COP_Sys_4 = HSPF_AFUE_COP_Sys_4.abbreviate(25);
}
heatCounter = heatCounter + 1;
}
//estarV31 = boolean.valueOf(hersAnalysis.Compliance[count].complianceStatus);
//estarV31Index = string.valueOf(hersAnalysis.Compliance[count].targetHers);
}
If (thisHousePlan.mechanicals.equipment[count2].equipmentType == 'BOILER'){
if(thisHousePlan.mechanicals.equipment[count2].heating.percentLoad > 0){
// system.debug('heat system');
if(heatCounter == 0){
Heating_Sys_1 = 'BOILER';
//Cooling_Capacity = '';
//Heating_Fuel
HSPF_AFUE_COP = string.valueOf(thisHousePlan.mechanicals.equipment[count2].heating.efficiency) + ' '+
string.valueOf(thisHousePlan.mechanicals.equipment[count2].heating.efficiencyType) ;
HSPF_AFUE_COP = HSPF_AFUE_COP.abbreviate(25);
}
if(heatCounter == 1){
//heatCounter = heatCounter + 1;
Heating_Sys_2 = 'BOILER';
//Cooling_Capacity = '';
//Heating_Fuel
HSPF_AFUE_COP_Sys_2 = string.valueOf(thisHousePlan.mechanicals.equipment[count2].heating.efficiency) + ' '+
string.valueOf(thisHousePlan.mechanicals.equipment[count2].heating.efficiencyType) ;
HSPF_AFUE_COP_Sys_2 = HSPF_AFUE_COP_Sys_2.abbreviate(25);
}
if(heatCounter == 2){
// heatCounter = heatCounter + 1;
Heating_Sys_3 = 'BOILER';
//Cooling_Capacity = '';
//Heating_Fuel
HSPF_AFUE_COP_Sys_3 = string.valueOf(thisHousePlan.mechanicals.equipment[count2].heating.efficiency) + ' '+
string.valueOf(thisHousePlan.mechanicals.equipment[count2].heating.efficiencyType) ;
HSPF_AFUE_COP_Sys_3 = HSPF_AFUE_COP_Sys_3.abbreviate(25);
}
if(heatCounter == 3){
// heatCounter = heatCounter + 1;
Heating_Sys_4 = 'BOILER';
//Cooling_Capacity = '';
//Heating_Fuel
HSPF_AFUE_COP_Sys_4 = string.valueOf(thisHousePlan.mechanicals.equipment[count2].heating.efficiency) + ' '+
string.valueOf(thisHousePlan.mechanicals.equipment[count2].heating.efficiencyType) ;
HSPF_AFUE_COP_Sys_4 = HSPF_AFUE_COP_Sys_4.abbreviate(25);
}
heatCounter = heatCounter + 1;
}
//estarV31 = boolean.valueOf(hersAnalysis.Compliance[count].complianceStatus);
//estarV31Index = string.valueOf(hersAnalysis.Compliance[count].targetHers);
}
If (thisHousePlan.mechanicals.equipment[count2].equipmentType == 'FURNACE'){
if(thisHousePlan.mechanicals.equipment[count2].heating.percentLoad > 0){
// system.debug('heat system');
if(heatCounter == 0){
Heating_Sys_1 = 'FURNACE';
//Cooling_Capacity = '';
//Heating_Fuel
HSPF_AFUE_COP = string.valueOf(thisHousePlan.mechanicals.equipment[count2].heating.efficiency) + ' '+
string.valueOf(thisHousePlan.mechanicals.equipment[count2].heating.efficiencyType) ;
HSPF_AFUE_COP = HSPF_AFUE_COP.abbreviate(25);
}
if(heatCounter == 1){
//heatCounter = heatCounter + 1;
Heating_Sys_2 = 'FURNACE';
//Cooling_Capacity = '';
//Heating_Fuel
HSPF_AFUE_COP_Sys_2 = string.valueOf(thisHousePlan.mechanicals.equipment[count2].heating.efficiency) + ' '+
string.valueOf(thisHousePlan.mechanicals.equipment[count2].heating.efficiencyType) ;
HSPF_AFUE_COP_Sys_2 = HSPF_AFUE_COP_Sys_2.abbreviate(25);
}
if(heatCounter == 2){
// heatCounter = heatCounter + 1;
Heating_Sys_3 = 'FURNACE';
//Cooling_Capacity = '';
//Heating_Fuel
HSPF_AFUE_COP_Sys_3 = string.valueOf(thisHousePlan.mechanicals.equipment[count2].heating.efficiency) + ' '+
string.valueOf(thisHousePlan.mechanicals.equipment[count2].heating.efficiencyType) ;
HSPF_AFUE_COP_Sys_3 = HSPF_AFUE_COP_Sys_3.abbreviate(25);
}
if(heatCounter == 3){
// heatCounter = heatCounter + 1;
Heating_Sys_4 = 'FURNACE';
//Cooling_Capacity = '';
//Heating_Fuel
HSPF_AFUE_COP_Sys_4 = string.valueOf(thisHousePlan.mechanicals.equipment[count2].heating.efficiency) + ' '+
string.valueOf(thisHousePlan.mechanicals.equipment[count2].heating.efficiencyType) ;
HSPF_AFUE_COP_Sys_4 = HSPF_AFUE_COP_Sys_4.abbreviate(25);
}
heatCounter = heatCounter + 1;
}
//estarV31 = boolean.valueOf(hersAnalysis.Compliance[count].complianceStatus);
//estarV31Index = string.valueOf(hersAnalysis.Compliance[count].targetHers);
}
If (thisHousePlan.mechanicals.equipment[count2].equipmentType == 'GROUND_SOURCE_HEAT_PUMP'){
if(thisHousePlan.mechanicals.equipment[count2].cooling.percentLoad > 0){