You need to sign in to do that
Don't have an account?
Tanu
need help to understand this apex class
here is a class - can anyone help me to explain the functionality of this apex class so that i can write test class for it..
public with sharing class CuAp_ContractDebtTransferCtrlr {
private static final String CLASS_NAME = 'CuAp_ContractDebtTransferCtrlr';
private static final String DEBUG = '[' + CLASS_NAME + '] ';
private static final List<String> transferReasonField = new List<string>{ GlUt_APIConstantsBillTransfer.TRANSFERREASONAPINAME};
private static final List<String> contractFields = new List<string>{
GlUt_APIConstantsContracts.CONTRACTNAMEAPINAME,
GlUt_APIConstantsContracts.BILLINGADDRESSAPINAME,
GlUt_APIConstantsContracts.CONTRACTBALANCEAPINAME
};
private static final List<String> billCalculationFields = new List<string>{
GlUt_APIConstantsBillCalculation.STATUSAPINAME
};
@AuraEnabled
public static List<List<GlAp_FieldProps>> retrieveTransferReasonDetails() {
List<List<GlAp_FieldProps>> twoColFormattedList = new List<List<GlAp_FieldProps>>();
try {
List<GLAp_FieldProps> transferReasonFieldProps = new List<GLAp_FieldProps>();
transferReasonFieldProps = GlAp_LightningDataAccess.getObjectsFieldProperties(GlUt_APIConstantsBillTransfer.BILLTRANSFERAPINAME, transferReasonField);
for(integer i=0; i < transferReasonFieldProps.size(); i = i+2){
List<GlAp_FieldProps> lstEntry = new List<GlAp_FieldProps>();
integer secondEntryIndex = i+1;
lstEntry.add(transferReasonFieldProps[i]);
if(secondEntryIndex < transferReasonFieldProps.size()){
lstEntry.add(transferReasonFieldProps[secondEntryIndex]);
}
twoColFormattedList.add(lstEntry);
}
} catch (exception e) {
GlUt_Logger.logException(e);
}
finally {
GlUt_Logger.writeLogsToDatabase();
}
return twoColFormattedList;
}
@AuraEnabled
public static List<List<GlAp_FieldProps>> retrieveContractFieldDetails() {
List<List<GlAp_FieldProps>> twoColFormattedList = new List<List<GlAp_FieldProps>>();
// Get the field properties for the Location object
List<GLAp_FieldProps> contractProperties = new List<GLAp_FieldProps>();
try {
contractProperties = GlAp_LightningDataAccess.getObjectsFieldProperties(GlUt_APIConstantsContracts.CONTRACTAPINAME, contractFields);
GlAp_FieldProps objFieldProp1 = new GlAp_FieldProps(true, false, true, false, CuAp_Constants.AMOUNTTOTRANSFER,CuAp_Constants.AMOUNTTOTRANSFERLABEL,
'number', false, false, GlUt_APIConstantsContracts.CONTRACTAPINAME);
contractProperties.add(objFieldProp1);
for(GlAp_FieldProps fieldProp : contractProperties ){
if (fieldProp.fieldName == GlUt_APIConstantsContracts.CONTRACTBALANCEAPINAME )
fieldProp.fieldLabel = LoAp_Constants.DEBTAMOUNTLABEL;
fieldProp.showLabel = true;
}
for(integer i=0; i < contractProperties.size(); i = i+2){
List<GlAp_FieldProps> lstEntry = new List<GlAp_FieldProps>();
integer secondEntryIndex = i+1;
lstEntry.add(contractProperties[i]);
if(secondEntryIndex < contractProperties.size()){
lstEntry.add(contractProperties[secondEntryIndex]);
}
twoColFormattedList.add(lstEntry);
}
} catch (exception e) {
GlUt_Logger.logException(e);
}
finally {
GlUt_Logger.writeLogsToDatabase();
}
return twoColFormattedList;
}
@AuraEnabled
public static BillingContract__c retrieveContractDetails(String ContractId) {
BillingContract__c objBillingContract ;
if(string.isNotBlank(ContractId)){
objBillingContract = (BillingContract__c)GlAp_LightningDataAccess.getRecord(GlUt_APIConstantsContracts.CONTRACTAPINAME,
ContractId,contractFields);
}
return objBillingContract;
}
@AuraEnabled
public static string transferDebts(String contractFromTransferID, String contractToTransferID, String transferReason, String amountToTransfer, string billCalculationId) {
String responseCode;
CuAp_BillTransferObject objBTData = new CuAp_BillTransferObject();
objBTData.BillTransfers = new List<CuAp_BillTransferObject.BillTransfers>();
CuAp_BillTransferObject.BillTransfers objBillTransfer = new CuAp_BillTransferObject.BillTransfers(contractToTransferID,contractFromTransferID,
transferReason,amountToTransfer,billCalculationId);
objBTData.BillTransfers.add(objBillTransfer);
String JSONPayload = JSON.serialize(objBTData);
try{
HttpResponse response = BlUt_HerokuWebservices.makeCallout(BlUt_HerokuWebservices.DEBT_TRANSFER, 2000, 'application/json', JSONPayload, 'PUT');
// handle response
if (response.getStatusCode() == 200) {
if(billCalculationId != null ){
BillCalculation__c objBillCalculation = (BillCalculation__c)GlAp_LightningDataAccess.getRecord(GlUt_APIConstantsBillCalculation.BILLCALCULATIONAPINAME,
billCalculationId,billCalculationFields);
objBillCalculation.Status__c = Label.BlIn_BillCalculationStatusPending;
objBillCalculation = (BillCalculation__c) GlUt_FieldSecurity.cleanseFields(objBillCalculation, false);
update objBillCalculation;
}
responseCode = Label.GlUt_OK;
}
else {
throw new AuraHandledException(Label.BlAp_BillCalcRequestError + response.getStatus());
}
}
catch (exception e) {
GlUt_Logger.logException(e);
throw new AuraHandledException(e.getMessage());
}
finally {
GlUt_Logger.writeLogsToDatabase();
}
return responseCode;
}
@AuraEnabled
public static Id createBillCalculation(string contractId){
BillCalculation__c billCalculationObj = GlUt_BillCalculationUtilities.createBillCalculation(contractId,Label.GlUt_Transfer,Label.BlIn_BillCalculationStatusNew);
return billCalculationObj.Id;
}
public class DebtTransferContainerWrapper{
@AuraEnabled
public List<List<GlAp_FieldProps>> transferReasonList;
@AuraEnabled
public List<List<GlAp_FieldProps>> billingContractFieldList;
@AuraEnabled
public BillingContract__c billingContractObj;
@AuraEnabled
public String billingAddressFormatted;
public DebtTransferContainerWrapper(){
this.transferReasonList = new List<List<GlAp_FieldProps>>();
this.billingContractFieldList = new List<List<GlAp_FieldProps>>();
this.billingContractObj = new BillingContract__c();
}
}
@AuraEnabled
public static DebtTransferContainerWrapper getInfoToDisplay(string billingContractRecordId) {
DebtTransferContainerWrapper objWrapper = new DebtTransferContainerWrapper();
if(billingContractRecordId != null ){
objWrapper.transferReasonList = retrieveTransferReasonDetails();
objWrapper.billingContractFieldList = retrieveContractFieldDetails();
objWrapper.billingContractObj = retrieveContractDetails(billingContractRecordId);
objWrapper.billingAddressFormatted = retrieveContractDetails(billingContractRecordId).BillingAddress__c.replace('<br>', '\r\n');
}
return objWrapper;
}
}
public with sharing class CuAp_ContractDebtTransferCtrlr {
private static final String CLASS_NAME = 'CuAp_ContractDebtTransferCtrlr';
private static final String DEBUG = '[' + CLASS_NAME + '] ';
private static final List<String> transferReasonField = new List<string>{ GlUt_APIConstantsBillTransfer.TRANSFERREASONAPINAME};
private static final List<String> contractFields = new List<string>{
GlUt_APIConstantsContracts.CONTRACTNAMEAPINAME,
GlUt_APIConstantsContracts.BILLINGADDRESSAPINAME,
GlUt_APIConstantsContracts.CONTRACTBALANCEAPINAME
};
private static final List<String> billCalculationFields = new List<string>{
GlUt_APIConstantsBillCalculation.STATUSAPINAME
};
@AuraEnabled
public static List<List<GlAp_FieldProps>> retrieveTransferReasonDetails() {
List<List<GlAp_FieldProps>> twoColFormattedList = new List<List<GlAp_FieldProps>>();
try {
List<GLAp_FieldProps> transferReasonFieldProps = new List<GLAp_FieldProps>();
transferReasonFieldProps = GlAp_LightningDataAccess.getObjectsFieldProperties(GlUt_APIConstantsBillTransfer.BILLTRANSFERAPINAME, transferReasonField);
for(integer i=0; i < transferReasonFieldProps.size(); i = i+2){
List<GlAp_FieldProps> lstEntry = new List<GlAp_FieldProps>();
integer secondEntryIndex = i+1;
lstEntry.add(transferReasonFieldProps[i]);
if(secondEntryIndex < transferReasonFieldProps.size()){
lstEntry.add(transferReasonFieldProps[secondEntryIndex]);
}
twoColFormattedList.add(lstEntry);
}
} catch (exception e) {
GlUt_Logger.logException(e);
}
finally {
GlUt_Logger.writeLogsToDatabase();
}
return twoColFormattedList;
}
@AuraEnabled
public static List<List<GlAp_FieldProps>> retrieveContractFieldDetails() {
List<List<GlAp_FieldProps>> twoColFormattedList = new List<List<GlAp_FieldProps>>();
// Get the field properties for the Location object
List<GLAp_FieldProps> contractProperties = new List<GLAp_FieldProps>();
try {
contractProperties = GlAp_LightningDataAccess.getObjectsFieldProperties(GlUt_APIConstantsContracts.CONTRACTAPINAME, contractFields);
GlAp_FieldProps objFieldProp1 = new GlAp_FieldProps(true, false, true, false, CuAp_Constants.AMOUNTTOTRANSFER,CuAp_Constants.AMOUNTTOTRANSFERLABEL,
'number', false, false, GlUt_APIConstantsContracts.CONTRACTAPINAME);
contractProperties.add(objFieldProp1);
for(GlAp_FieldProps fieldProp : contractProperties ){
if (fieldProp.fieldName == GlUt_APIConstantsContracts.CONTRACTBALANCEAPINAME )
fieldProp.fieldLabel = LoAp_Constants.DEBTAMOUNTLABEL;
fieldProp.showLabel = true;
}
for(integer i=0; i < contractProperties.size(); i = i+2){
List<GlAp_FieldProps> lstEntry = new List<GlAp_FieldProps>();
integer secondEntryIndex = i+1;
lstEntry.add(contractProperties[i]);
if(secondEntryIndex < contractProperties.size()){
lstEntry.add(contractProperties[secondEntryIndex]);
}
twoColFormattedList.add(lstEntry);
}
} catch (exception e) {
GlUt_Logger.logException(e);
}
finally {
GlUt_Logger.writeLogsToDatabase();
}
return twoColFormattedList;
}
@AuraEnabled
public static BillingContract__c retrieveContractDetails(String ContractId) {
BillingContract__c objBillingContract ;
if(string.isNotBlank(ContractId)){
objBillingContract = (BillingContract__c)GlAp_LightningDataAccess.getRecord(GlUt_APIConstantsContracts.CONTRACTAPINAME,
ContractId,contractFields);
}
return objBillingContract;
}
@AuraEnabled
public static string transferDebts(String contractFromTransferID, String contractToTransferID, String transferReason, String amountToTransfer, string billCalculationId) {
String responseCode;
CuAp_BillTransferObject objBTData = new CuAp_BillTransferObject();
objBTData.BillTransfers = new List<CuAp_BillTransferObject.BillTransfers>();
CuAp_BillTransferObject.BillTransfers objBillTransfer = new CuAp_BillTransferObject.BillTransfers(contractToTransferID,contractFromTransferID,
transferReason,amountToTransfer,billCalculationId);
objBTData.BillTransfers.add(objBillTransfer);
String JSONPayload = JSON.serialize(objBTData);
try{
HttpResponse response = BlUt_HerokuWebservices.makeCallout(BlUt_HerokuWebservices.DEBT_TRANSFER, 2000, 'application/json', JSONPayload, 'PUT');
// handle response
if (response.getStatusCode() == 200) {
if(billCalculationId != null ){
BillCalculation__c objBillCalculation = (BillCalculation__c)GlAp_LightningDataAccess.getRecord(GlUt_APIConstantsBillCalculation.BILLCALCULATIONAPINAME,
billCalculationId,billCalculationFields);
objBillCalculation.Status__c = Label.BlIn_BillCalculationStatusPending;
objBillCalculation = (BillCalculation__c) GlUt_FieldSecurity.cleanseFields(objBillCalculation, false);
update objBillCalculation;
}
responseCode = Label.GlUt_OK;
}
else {
throw new AuraHandledException(Label.BlAp_BillCalcRequestError + response.getStatus());
}
}
catch (exception e) {
GlUt_Logger.logException(e);
throw new AuraHandledException(e.getMessage());
}
finally {
GlUt_Logger.writeLogsToDatabase();
}
return responseCode;
}
@AuraEnabled
public static Id createBillCalculation(string contractId){
BillCalculation__c billCalculationObj = GlUt_BillCalculationUtilities.createBillCalculation(contractId,Label.GlUt_Transfer,Label.BlIn_BillCalculationStatusNew);
return billCalculationObj.Id;
}
public class DebtTransferContainerWrapper{
@AuraEnabled
public List<List<GlAp_FieldProps>> transferReasonList;
@AuraEnabled
public List<List<GlAp_FieldProps>> billingContractFieldList;
@AuraEnabled
public BillingContract__c billingContractObj;
@AuraEnabled
public String billingAddressFormatted;
public DebtTransferContainerWrapper(){
this.transferReasonList = new List<List<GlAp_FieldProps>>();
this.billingContractFieldList = new List<List<GlAp_FieldProps>>();
this.billingContractObj = new BillingContract__c();
}
}
@AuraEnabled
public static DebtTransferContainerWrapper getInfoToDisplay(string billingContractRecordId) {
DebtTransferContainerWrapper objWrapper = new DebtTransferContainerWrapper();
if(billingContractRecordId != null ){
objWrapper.transferReasonList = retrieveTransferReasonDetails();
objWrapper.billingContractFieldList = retrieveContractFieldDetails();
objWrapper.billingContractObj = retrieveContractDetails(billingContractRecordId);
objWrapper.billingAddressFormatted = retrieveContractDetails(billingContractRecordId).BillingAddress__c.replace('<br>', '\r\n');
}
return objWrapper;
}
}