-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathekotropeSchedulable.apex
125 lines (110 loc) · 5.91 KB
/
ekotropeSchedulable.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
/*was serhSchedulable */
global class ekotropeSchedulable implements Schedulable{
global void execute(SchedulableContext sc){
list<Project__c> updateLevenString = new list<Project__c>();
for(Project__c existingProject : [Select name, id, zip_code__c, state__c,
city__c, street_address__c
FROM Project__c where Levenshtein_String__c = null]) //and RecordTypeId='??????????????????'
{
String projName, street, city, state;
projName = existingProject.name;
street = existingProject.street_address__c;
city = existingProject.city__c;
state = existingProject.state__c;
string levenString = ekotropeSync.normalizeLechString(projName, street, city, state);
//system.debug(lechString);
existingProject.LevenShtein_String__c = levenString;
updateLevenString.add(existingProject);
}
update updateLevenString;
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;
}
list<string> buildingTypes = new list<string>();
buildingTypes.add('EkotropeAsModeled');
buildingTypes.add('HERSReference');
buildingTypes.add('DOEZeroEnergyReadyTarget');
buildingTypes.add('IECC2015_5ACH50Reference');
buildingTypes.add('Virginia2015Reference');
list<string> codes = new list<string>();
codes.add('TaxCredit45L');
codes.add('IECC2015Prescriptive');
codes.add('IECC2015Performance');
codes.add('Virginia2015Performance');
codes.add('Virginia2015Prescriptive');
codes.add('Virginia2015ERI');
codes.add('EnergyStarV3');
codes.add('EnergyStarV31');//just for mf?
codes.add('EnergyStarMFV1');
codes.add('DOEZeroEnergyReady');
list<string> statusList = new list<string>();
if (Test.isRunningTest()){
system.debug('Need to write complicated test code, or I can do this');
statusList.add('SUBMITTED_FOR_QA');
} else{
statusList.add('SUBMITTED_FOR_QA');
statusList.add('SUBMITTED_TO_REGISTRY');
}
ekotropeSync updateNewProjects = new ekotropeSync();
updateNewProjects.setAuthorization();
updateNewProjects.setCodesToCheck(codes);
updateNewProjects.setVariables(statusList);
updateNewProjects.setEnergyDataName('HERS');
//will need to make different energy data records
// one for HERS data or we put everything HERS (3) plus the three additional records.
updateNewProjects.setBuildingRun(buildingTypes);
System.debug('here');
Id newProjectBatchId = Database.executeBatch(updateNewProjects,10);
list<string> mfStatusList = new list<string>();
if (Test.isRunningTest()){
system.debug('Need to write complicated test code or I can do this');
mfStatusList.add('SUBMITTED_FOR_QA');
} else{
mfStatusList.add('SUBMITTED_FOR_QA');
mfStatusList.add('SUBMITTED_TO_REGISTRY');
mfStatusList.add('UNREGISTERED');
mfStatusList.add('REGISTERED_WITH_PROVIDER');
}
ecmfSync updateECMF = new ecmfSync();
updateECMF.setAuthorization();
updateECMF.setCodesToCheck(codes);
updateECMF.setVariables(mfStatusList);
updateECMF.setBuildingRun(buildingTypes);
System.debug('here');
Id newProjectBatchId_ecmf = Database.executeBatch(updateECMF,15);
}
}