Skip to content

Commit

Permalink
Merge pull request #6824 from SalesforceFoundation/feature/238__rdMig…
Browse files Browse the repository at this point in the history
…rationRemoveTotal

Removing "total" from RD Migration JSON to free up space in field
  • Loading branch information
daniel-fuller authored Feb 7, 2022
2 parents c24cf38 + 4e49702 commit d561f09
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ public abstract class RD2_DataMigrationBase_BATCH implements Database.Batchable<
*/
public void finish(Database.BatchableContext context) {
UTIL_BatchJobService.JobSummary summary = new UTIL_BatchJobService.JobSummary(batchJobId)
.withTotalRecords(totalRecords)
.withTotalRecordsProcessed(totalRecords - totalRecordsFailed)
.withTotalRecordsFailed(totalRecordsFailed)
.withCompletedDate(Datetime.now());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,14 @@ private with sharing class RD2_DataMigrationEnablement_TEST {
Boolean isDryRunMode = false;
UTIL_BatchJobService.JobSummary summary =
new UTIL_BatchJobService.JobSummary(BATCH_ID)
.withTotalRecords(2)
.withTotalRecordsProcessed(2);

batchJob.saveSummary(summary, isDryRunMode);

summary = batchJob.getSummary(BATCH_ID, MIGRATION_BATCH_CLASS);
System.assertNotEquals(null, summary, 'Summary should be returned');
System.assertEquals(BATCH_ID, summary.batchId, 'Batch Id should match: ' + summary);
System.assertEquals(2, summary.total, 'Total records should match: ' + summary);
System.assertEquals(2, summary.processed, 'Processed records should match: ' + summary);

summary = batchJob.getSummary(BATCH_ID, DRY_RUN_MIGRATION_BATCH_CLASS);
System.assertEquals(null, summary, 'Summary should not exist for dry run');
Expand All @@ -73,7 +72,6 @@ private with sharing class RD2_DataMigrationEnablement_TEST {
Boolean isDryRunMode = true;
UTIL_BatchJobService.JobSummary summary =
new UTIL_BatchJobService.JobSummary(BATCH_ID)
.withTotalRecords(2)
.withTotalRecordsProcessed(2)
.withCompletedDate(MIGRATION_TIME);

Expand All @@ -82,7 +80,7 @@ private with sharing class RD2_DataMigrationEnablement_TEST {
summary = batchJob.getSummary(BATCH_ID, DRY_RUN_MIGRATION_BATCH_CLASS);
System.assertNotEquals(null, summary, 'Summary should be returned');
System.assertEquals(BATCH_ID, summary.batchId, 'Batch Id should match: ' + summary);
System.assertEquals(2, summary.total, 'Total records should match: ' + summary);
System.assertEquals(2, summary.processed, 'Processed records should match: ' + summary);
System.assertEquals(MIGRATION_TIME, summary.completedDate, 'Completed time shhould match: ' + summary);

summary = batchJob.getSummary(BATCH_ID, MIGRATION_BATCH_CLASS);
Expand Down
36 changes: 30 additions & 6 deletions force-app/main/default/classes/RD2_DataMigration_TEST.cls
Original file line number Diff line number Diff line change
Expand Up @@ -1847,7 +1847,6 @@ private class RD2_DataMigration_TEST {

UTIL_BatchJobService.JobSummary expectedSummary =
new UTIL_BatchJobService.JobSummary(jobId)
.withTotalRecords(2)
.withTotalRecordsProcessed(1)
.withTotalRecordsFailed(1);

Expand Down Expand Up @@ -2062,8 +2061,8 @@ private class RD2_DataMigration_TEST {
}

/**
* @description Verifies that a Legacy Fixed Length RD is converted without metadata for Fixed type.
*/
* @description Verifies that a Legacy Fixed Length RD is converted without metadata for Fixed type.
*/
@IsTest
private static void shouldConvertFixedLengthRDWithoutFixedPicklistOption() {
final Integer installments = 12;
Expand All @@ -2090,6 +2089,34 @@ private class RD2_DataMigration_TEST {
}
}

/**
* @description Verifies that Migration State can be set even when the number of records is high
*/
@isTest
private static void shouldNotCauseErrorIfMigrationRecordCountIsVeryLarge() {
Integer totalRecordsFailed = 1000;
Integer totalRecordsProcessed = 100000000;

UTIL_BatchJobService.JobSummary summary =
new UTIL_BatchJobService.JobSummary(UTIL_BatchJobService_TEST.MOCK_BATCH_ID)
.withTotalRecordsProcessed(totalRecordsProcessed)
.withTotalRecordsFailed(totalRecordsFailed)
.withCompletedDate(Datetime.now());

Map<String, UTIL_BatchJobService.JobSummary> summaryByType =
new Map<String, UTIL_BatchJobService.JobSummary> {
'dryRun' => summary,
'run' => summary
};

npe03__Recurring_Donations_Settings__c rdSettings =
new npe03__Recurring_Donations_Settings__c (
RecurringDonations2MigrationState__c = JSON.serialize(summaryByType)
);

System.assert(rdSettings.RecurringDonations2MigrationState__c.length() <= 255,
'RD Migration State String should be less than or equal to 255');
}


// HELPER METHODS
Expand Down Expand Up @@ -2399,7 +2426,6 @@ private class RD2_DataMigration_TEST {
private static void assertBatchSummarySuccess(Id jobId, Integer totalProcessed) {
UTIL_BatchJobService.JobSummary expectedSummary =
new UTIL_BatchJobService.JobSummary(jobId)
.withTotalRecords(totalProcessed)
.withTotalRecordsProcessed(totalProcessed)
.withTotalRecordsFailed(0);

Expand All @@ -2415,7 +2441,6 @@ private class RD2_DataMigration_TEST {
private static void assertBatchSummaryFailed(Id jobId, Integer totalFailed) {
UTIL_BatchJobService.JobSummary expectedSummary =
new UTIL_BatchJobService.JobSummary(jobId)
.withTotalRecords(totalFailed)
.withTotalRecordsProcessed(0)
.withTotalRecordsFailed(totalFailed);

Expand All @@ -2437,7 +2462,6 @@ private class RD2_DataMigration_TEST {

UTIL_BatchJobService.JobSummary summary = summaryByType.values()[0];
System.assertEquals(expectedSummary.batchId, summary.batchId, 'Batch Id should match: ' + summary);
System.assertEquals(expectedSummary.total, summary.total, 'Total Records should match: ' + summary);
System.assertEquals(expectedSummary.processed, summary.processed, 'Total Records Processed should match: ' + summary);
System.assertEquals(expectedSummary.failed, summary.failed, 'Total Records Failed should match: ' + summary);
}
Expand Down
4 changes: 0 additions & 4 deletions force-app/main/default/classes/STG_SettingsManager_TEST.cls
Original file line number Diff line number Diff line change
Expand Up @@ -1961,7 +1961,6 @@ private with sharing class STG_SettingsManager_TEST {
RD2_EnablementService_TEST.setRecurringDonations2Enabled();

UTIL_BatchJobService.JobSummary summary = new UTIL_BatchJobService.JobSummary(UTIL_BatchJobService_TEST.MOCK_BATCH_ID)
.withTotalRecords(2)
.withTotalRecordsProcessed(2);

Map<String, UTIL_BatchJobService.JobSummary> summaryByType = new Map<String, UTIL_BatchJobService.JobSummary> {
Expand Down Expand Up @@ -1990,7 +1989,6 @@ private with sharing class STG_SettingsManager_TEST {
RD2_EnablementService_TEST.setRecurringDonations2Enabled();

UTIL_BatchJobService.JobSummary summary = new UTIL_BatchJobService.JobSummary(UTIL_BatchJobService_TEST.MOCK_BATCH_ID)
.withTotalRecords(2)
.withTotalRecordsProcessed(2);

Map<String, UTIL_BatchJobService.JobSummary> summaryByType = new Map<String, UTIL_BatchJobService.JobSummary> {
Expand Down Expand Up @@ -2023,7 +2021,6 @@ private with sharing class STG_SettingsManager_TEST {
RD2_EnablementService_TEST.setRecurringDonations2Enabled();

UTIL_BatchJobService.JobSummary summary = new UTIL_BatchJobService.JobSummary(UTIL_BatchJobService_TEST.MOCK_BATCH_ID)
.withTotalRecords(2)
.withTotalRecordsProcessed(2);

Map<String, UTIL_BatchJobService.JobSummary> summaryByType = new Map<String, UTIL_BatchJobService.JobSummary> {
Expand Down Expand Up @@ -2055,7 +2052,6 @@ private with sharing class STG_SettingsManager_TEST {
RD2_EnablementService_TEST.setRecurringDonations2Enabled();

UTIL_BatchJobService.JobSummary summary = new UTIL_BatchJobService.JobSummary(UTIL_BatchJobService_TEST.MOCK_BATCH_ID)
.withTotalRecords(2)
.withTotalRecordsProcessed(2);

Map<String, UTIL_BatchJobService.JobSummary> summaryByType = new Map<String, UTIL_BatchJobService.JobSummary> {
Expand Down
11 changes: 0 additions & 11 deletions force-app/main/default/classes/UTIL_BatchJobService.cls
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,6 @@ public without sharing class UTIL_BatchJobService {
*/
public class JobSummary {
public Id batchId;
public Integer total = 0;
public Integer processed = 0;
public Integer failed = 0;
public Datetime completedDate;
Expand All @@ -475,16 +474,6 @@ public without sharing class UTIL_BatchJobService {
this.batchId = batchId;
}

/**
* @description Sets number of records selected
* @param total Number of records selected
* @return JobSummary
*/
public JobSummary withTotalRecords(Integer total) {
this.total = total;
return this;
}

/**
* @description Sets number of records processed
* @param processed Number of records processed
Expand Down
3 changes: 0 additions & 3 deletions force-app/main/default/classes/UTIL_BatchJobService_TEST.cls
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,11 @@ public with sharing class UTIL_BatchJobService_TEST {

UTIL_BatchJobService.JobSummary summary =
new UTIL_BatchJobService.JobSummary(MOCK_BATCH_ID)
.withTotalRecords(total)
.withTotalRecordsProcessed(processed)
.withTotalRecordsFailed(failed)
.withCompletedDate(completedTime);

System.assertEquals(MOCK_BATCH_ID, summary.batchId, 'Batch Id should match');
System.assertEquals(total, summary.total, 'Total Records should match');
System.assertEquals(processed, summary.processed, 'Total Records Processed should match');
System.assertEquals(failed, summary.failed, 'Total Records Failed should match');
System.assertEquals(completedTime, summary.completedDate, 'Completed Date should match');
Expand Down Expand Up @@ -266,7 +264,6 @@ public with sharing class UTIL_BatchJobService_TEST {
System.assertNotEquals(null, batchJob.summary, 'Batch Job summary should be returned');

System.assertEquals(jobId, batchJob.summary.batchId, 'Batch Id should match: ' + batchJob.summary);
System.assertEquals(1, batchJob.summary.total, 'Total Records should match: ' + batchJob.summary);
System.assertEquals(1, batchJob.summary.processed, 'Total Records Processed should match: ' + batchJob.summary);
System.assertEquals(0, batchJob.summary.failed, 'Total Records Failed should match: ' + batchJob.summary);
System.assertNotEquals(null, batchJob.summary.completedDate, 'The completed time should be stored');
Expand Down
12 changes: 11 additions & 1 deletion force-app/main/default/lwc/batchProgress/batchProgress.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default class BatchProgress extends LightningElement {
loadBatchJob({ className: this.className })
.then((data) => {
this.prevBatchJob = this.batchJob;
this.batchJob = JSON.parse(data);
this.batchJob = this.setTotalRecords(JSON.parse(data));

if (isNull(this.batchJob)) {
return;
Expand Down Expand Up @@ -96,6 +96,16 @@ export default class BatchProgress extends LightningElement {
}, this.pollingTimeout, self);
}

/***
* @description Sets the total value as the sum of processed and failed
*/
setTotalRecords(data) {
if(!isNull(data)) {
data.summary.total = data.summary.processed + data.summary.failed;
}
return data;
}

/***
* @description Notifies other components about the batch status change
*/
Expand Down

0 comments on commit d561f09

Please sign in to comment.