Skip to content

Commit

Permalink
#296 updating mcdo_CreateEnvironment to create the environments, the …
Browse files Browse the repository at this point in the history
…environment variables and the system properties
  • Loading branch information
Daniel Ventura committed Dec 20, 2022
1 parent 9a6edd6 commit 9e4797c
Showing 1 changed file with 78 additions and 15 deletions.
93 changes: 78 additions & 15 deletions force-app/main/default/classes/mcdo_CreateEnvironments.cls
Original file line number Diff line number Diff line change
@@ -1,28 +1,91 @@
/**
* This class is used by the MC Init function, g
* This class is used by the MC Init function,
* responsible for creating all environments
*/
global class mcdo_CreateEnvironments implements copado.JobExecutionCallback {
global void execute(copado__JobExecution__c job, String status) {
global class mcdo_CreateEnvironments implements copado.JobExecutionCallback {
global void execute(copado__JobExecution__c job, String status) {
// in case of error:
if(status == 'Error') {
// handle Error

// handle Error
System.debug('Error: ' + job.copado__ErrorMessage__c);

} else if(status == 'Successful') {
// handle Success
System.debug('Job: ' + job);
System.debug('Job.copado__DataJson__c: ' + job.copado__DataJson__c);
// TODO: create all the needed environments
List<Object> dataJson = (List<Object>)JSON.deserializeUntyped(job.copado__DataJson__c);
System.debug(dataJson);
for(Object dt : dataJson){
System.debug('Entered the for loop');
Map<String,Object> data = (Map<String,Object>)dt;
System.debug(data.get('Name'));
}

// handle Success
// Go through the environment json array
List<Object> dataJson = (List<Object>)JSON.deserializeUntyped(job.copado__DataJson__c);
for(Object env : dataJson){

Map<String,Object> environment = (Map<String,Object>)env;
String envName = environment.get('Name').toString();

// TODO: CREATE ENVIRONMENT IN HERE
copado__Environment__c environmentCopado = new copado__Environment__c(
copado__Platform__c='Marketing Cloud',
Name=envName
);
insert environmentCopado;

// Create a list of environment variables so we can add all of them in here and then insert them
// this way we will avoid to get into governor limits
List<copado__Environmental_Variable__c> envVarList = new List<copado__Environmental_Variable__c>();

// Go through the environmentVariables json array
List<Object> environmentVariables = (List<Object>) environment.get('environmentVariables');
for(Object var: environmentVariables){
Map<String,Object> variables = (Map<String,Object>)var;
String envVarName = variables.get('name').toString();
String envVarValue = variables.get('value').toString();

// create the environment variable
copado__Environmental_Variable__c environmentVariableCopado = new copado__Environmental_Variable__c(
copado__Environment__c=environmentCopado.id,
Name=envVarName,
copado__Value__c=envVarValue
);

//add it to the list
envVarList.add(environmentVariableCopado);
}

//insert the list
insert envVarList;

// Create a list of system properties as well
// this way we will avoid to get into governor limits
List<copado__System_Property__c> sysPropList = new List<copado__System_Property__c>();

// Go through the systemProperties json array
List<Object> systemProperties = (List<Object>) environment.get('properties');
for(Object prop: systemProperties){
Map<String,Object> properties = (Map<String,Object>)prop;
String sysPropName = properties.get('name').toString();
String sysPropApiName = properties.get('apiName').toString();
String sysPropValue = properties.get('value').toString();
Boolean sysPropHideValue = Boolean.valueOf(properties.get('hideValue'));

// create the system property
copado__System_Property__c systemPropertyCopado = new copado__System_Property__c(
copado__Environment__c=environmentCopado.id,
Name=sysPropName,
copado__API_Name__c=sysPropApiName,
copado__Value__c=sysPropValue,
copado__Is_Sensitive__c=sysPropHideValue
);

//add it to the list
sysPropList.add(systemPropertyCopado);
}

//insert the list
insert sysPropList;
}
} else {

// handle In progress if necessary
System.debug('still in progress...');

}
}
}

0 comments on commit 9e4797c

Please sign in to comment.