Skip to content

Commit

Permalink
Merge 9360527 into feature/238__rdMigrationRemoveTotal
Browse files Browse the repository at this point in the history
  • Loading branch information
salesforce-org-metaci[bot] authored Feb 7, 2022
2 parents 6812a92 + 9360527 commit 4e49702
Show file tree
Hide file tree
Showing 16 changed files with 612 additions and 15 deletions.
34 changes: 34 additions & 0 deletions cumulusci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,40 @@ flows:
2:
task: update_admin_profile

enable_gift_entry:
description: Enable the Gift Entry feature.
group: NPSP
steps:
1:
flow: enable_advanced_mapping
2:
task: execute_anon
options:
apex: >
String namespace = ('%%%NAMESPACE%%%').replace('__','');
Type t = Type.forName(namespace, 'Callable_Api');
Callable apiClass = (Callable)t.newInstance();
apiClass.call('settings.enablegiftentry', null);
enable_advanced_mapping:
description: Enable the BDI Advanced Mapping feature.
group: NPSP
steps:
1:
task: execute_anon
options:
apex: >
String namespace = ('%%%NAMESPACE%%%').replace('__','');
Type t = Type.forName(namespace, 'Callable_Api');
Callable apiClass = (Callable)t.newInstance();
apiClass.call('settings.enableadvancedmapping', null);
2:
task: custom_settings_value_wait
options:
object: "%%%NAMESPACE%%%Data_Import_Settings__c"
field: "%%%NAMESPACE%%%Field_Mapping_Method__c"
value: "Data Import Field Mapping"

enable_rd2:
description: 'Fully configures and enables a Scratch org with Enhanced Recurring Donations (unmanaged code only)'
group: NPSP
Expand Down
14 changes: 14 additions & 0 deletions documentation/automation.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,20 @@ as well as many other features needed to define the workspace for the org's inte
| `enable_crlp` | Task | Enable the NPSP Customizable Rollups feature (works for both Managed and Unmanaged) |
| `enable_incremental_rollups` | Task | Configure NPSP Customizable Rollups to activate Incremental Rollups |

### Advanced Mapping

| Name | Type | Description |
| ----------------------------- | ---- | -------------------------------------------------------------------------------------------- |
| `enable_advanced_mapping` | Flow | Enable the BDI Advanced Mapping feature (unmanaged code only).
| `enable_advanced_mapping_managed` | Flow | Enable the BDI Advanced Mapping feature (managed package only)

### Gift Entry

| Name | Type | Description |
| ----------------------------- | ---- | -------------------------------------------------------------------------------------------- |
| `enable_gift_entry` | Flow | Enable the Gift Entry feature (unmanaged code only).
| `enable_gift_entry_managed` | Flow | Enable the Gift Entry feature (managed package only)

### Enhanced Recurring Donations

| Name | Type | Description |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
Copyright (c) 2022, Salesforce.org
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Salesforce.org nor the names of
its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @author: Salesforce.org
* @date: 2022
* @description: Service to enable the advanced mapping feature
*/
public with sharing class AdvancedMappingEnablementService {

@TestVisible
private BDI_MigrationMappingUtility migrationMappingUtility {
get {
if (migrationMappingUtility == null) {
migrationMappingUtility = new BDI_MigrationMappingUtility(new BDI_MigrationMappingHelper());
}
return migrationMappingUtility;
}
set;
}

public Id enable() {
migrationMappingUtility.migrateHelpTextToCustomMetadata();

Id deploymentId = CMT_MetadataAPI.deployMetadata(
migrationMappingUtility.queuedMetadataTypesForDeploy,
new BDI_MigrationMappingUtility.DeploymentCallback());

return deploymentId;
}

public Boolean isEnabled() {
Data_Import_Settings__c dataImportSettings = UTIL_CustomSettingsFacade.getDataImportSettings();

return dataImportSettings.Field_Mapping_Method__c == BDI_MigrationMappingUtility.DATA_IMPORT_FIELD_MAPPING;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>53.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
*
* Copyright (c) 2022, Salesforce.org
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Salesforce.org nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* /
*/
/**
* @author Salesforce.org
* @date 2022
* @description StubProvider mock for tests
*/
public with sharing class AdvancedMappingEnablementServiceMock implements StubProvider {
public Boolean enableAdvancedMappingCalled = false;
public Boolean isEnabled = false;

public void setEnabled() {
isEnabled = true;
}

public Object handleMethodCall(
Object stubbedObject,
String stubbedMethodName,
Type returnType,
List<Type> listOfParamTypes,
List<String> listOfParamNames,
List<Object> listOfArgs) {

switch on (stubbedMethodName) {
when 'enable' {
enableAdvancedMappingCalled = true;
}
when 'isEnabled' {
return isEnabled;
}
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>53.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
Copyright (c) 2022, Salesforce.org
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Salesforce.org nor the names of
its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
@IsTest
private class AdvancedMappingEnablementService_TEST {

@IsTest
private static void shouldExecuteHelpTextMigrationOnEnable() {
AdvancedMappingEnablementService mappingService = new AdvancedMappingEnablementService();
BDI_MigrationMappingUtilityMock migrationMappingUtilityMock = new BDI_MigrationMappingUtilityMock();
mappingService.migrationMappingUtility = stubFor(migrationMappingUtilityMock);
mappingService.migrationMappingUtility.queuedMetadataTypesForDeploy = getMockMetadata();

Test.startTest();
mappingService.enable();
Test.stopTest();

System.assert(migrationMappingUtilityMock.migrateHelpTextCalled, 'The migration of help text to custom ' +
'metadata should execute.');
}

@IsTest
private static void shouldUpdateCustomSettingsForDataImportFieldMapping() {
BDI_MigrationMappingUtility.DeploymentCallback callback = new BDI_MigrationMappingUtility.DeploymentCallback();
TestingDeployCallbackContext context = new TestingDeployCallbackContext();

Metadata.DeployResult deployResult = new Metadata.DeployResult();
deployResult.status = Metadata.DeployStatus.Succeeded;

Test.startTest();
callback.handleResult(deployResult, context);
Test.stopTest();

Data_Import_Settings__c dataImportSettings = UTIL_CustomSettingsFacade.getDataImportSettings();

System.assertNotEquals(Metadata.DeployStatus.Succeeded.name(), dataImportSettings.CMT_API_Status__c);


System.assert(new AdvancedMappingEnablementService().isEnabled(), 'Advanced mapping should be enabled.');
}

private static List<Metadata.CustomMetadata> getMockMetadata() {
List<Metadata.CustomMetadata> mockCustomMetadataRecords = new List<Metadata.CustomMetadata>();
Metadata.CustomMetadata mockCustomMetadata1 = new Metadata.CustomMetadata();

mockCustomMetadata1.description = 'test';
mockCustomMetadata1.fullName = 'test_metadata';
mockCustomMetadata1.label = 'test';
mockCustomMetadataRecords.add(mockCustomMetadata1);

return mockCustomMetadataRecords;
}

private static BDI_MigrationMappingUtility stubFor(BDI_MigrationMappingUtilityMock migrationMappingUtilityMock) {

return (BDI_MigrationMappingUtility) Test.createStub(
BDI_MigrationMappingUtility.class, migrationMappingUtilityMock);
}

private class BDI_MigrationMappingUtilityMock implements StubProvider {
private Boolean migrateHelpTextCalled = false;

public Object handleMethodCall(Object stubbedObject, String stubbedMethodName, Type returnType,
List<Type> listOfParamTypes, List<String> listOfParamNames, List<Object> listOfArgs) {

switch on (stubbedMethodName) {
when 'migrateHelpTextToCustomMetadata' {
migrateHelpTextCalled = true;
}
}

return null;
}
}

private class TestingDeployCallbackContext extends Metadata.DeployCallbackContext {
public override Id getCallbackJobId() {
return '000000000122345';
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>53.0</apiVersion>
<status>Active</status>
</ApexClass>
44 changes: 42 additions & 2 deletions force-app/main/default/classes/Callable_API.cls
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,29 @@ global with sharing class Callable_API implements System.Callable {
********************************************************************************************************/
public class MalformedMethodInvocationException extends Exception {}


@TestVisible
private AdvancedMappingEnablementService advancedMappingEnablementService {
get {
if (advancedMappingEnablementService == null) {
advancedMappingEnablementService = new AdvancedMappingEnablementService();
}
return advancedMappingEnablementService;
}
set;
}

@TestVisible
private GiftEntryEnablementService giftEntryEnablementService {
get {
if (giftEntryEnablementService == null) {
giftEntryEnablementService = new GiftEntryEnablementService();
}
return giftEntryEnablementService;
}
set;
}

/*******************************************************************************************************
* @description call function implementation of the callable Interface will dispatch to the appropriate
* action handler based on the action text
Expand Down Expand Up @@ -159,7 +182,25 @@ global with sharing class Callable_API implements System.Callable {
// It returns the Job ID of the Scheduled Job.
return CallableApiApexDelegationService.handleApexScheduleJob(params);

} when else {
} when 'settings.enableadvancedmapping' {
if (advancedMappingEnablementService.isEnabled()) {
return null;
}

advancedMappingEnablementService.enable();

return null;

} when 'settings.enablegiftentry' {
if (giftEntryEnablementService.isEnabled()) {
return null;
}

giftEntryEnablementService.enable();

return null;
}
when else {
throw new MalformedMethodInvocationException(
String.format(System.Label.CallableApiMethodNotImplemented, new List<String> { action })
);
Expand All @@ -169,5 +210,4 @@ global with sharing class Callable_API implements System.Callable {
// if the action does not return a value then return success
return true;
}

}
Loading

0 comments on commit 4e49702

Please sign in to comment.