Skip to content

Commit

Permalink
Merge 5f0803b into feature/242
Browse files Browse the repository at this point in the history
  • Loading branch information
salesforce-org-metaci[bot] authored Nov 17, 2023
2 parents 7c72321 + 5f0803b commit bb5a983
Show file tree
Hide file tree
Showing 20 changed files with 421 additions and 62 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Salesforce / SFDX / CCI
.cci
.sfdx
.sf
/src.orig
/src

Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ PMM AND SFDO BASE ARE NON-SFDC APPLICATIONS OR THIRD-PARTY APPLICATIONS, AND NOT
SFDC WILL NOT HAVE ANY LIABILITY ARISING OUT OF OR RELATED TO YOUR USE OF PMM OR SFDO BASE FOR ANY DIRECT DAMAGES OR FOR ANY LOST PROFITS, REVENUES, GOODWILL OR INDIRECT, SPECIAL, INCIDENTAL, CONSEQUENTIAL, EXEMPLARY, COVER, BUSINESS INTERRUPTION OR PUNITIVE DAMAGES, WHETHER AN ACTION IS IN CONTRACT OR TORT AND REGARDLESS OF THE THEORY OF LIABILITY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES OR IF A REMEDY OTHERWISE FAILS OF ITS ESSENTIAL PURPOSE. THE FOREGOING DISCLAIMER WILL NOT APPLY TO THE EXTENT PROHIBITED BY LAW. SFDC DISCLAIMS ALL LIABILITY AND INDEMNIFICATION OBLIGATIONS FOR ANY HARM OR DAMAGES CAUSED BY ANY THIRD-PARTY HOSTING PROVIDERS.

THIS AGREEMENT SHALL BE GOVERNED EXCLUSIVELY BY, AND CONSTRUED EXCLUSIVELY IN ACCORDANCE WITH, THE LAWS OF THE UNITED STATES AND THE STATE OF CALIFORNIA, WITHOUT REGARD TO ITS CONFLICT OF LAWS PROVISIONS. THE STATE AND FEDERAL COURTS LOCATED IN SAN FRANCISCO, CALIFORNIA SHALL HAVE EXCLUSIVE JURISDICTION TO ADJUDICATE ANY DISPUTE ARISING OUT OF OR RELATING TO THIS AGREEMENT. EACH PARTY HEREBY CONSENTS TO THE JURISDICTION OF SUCH COURTS AND WAIVES ANY RIGHT IT MAY OTHERWISE HAVE TO CHALLENGE THE APPROPRIATENESS OF SUCH FORUMS.

4 changes: 2 additions & 2 deletions force-app/main/default/classes/ProgramEngagementSelector.cls
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public with sharing class ProgramEngagementSelector {
}

List<ProgramEngagement__c> queriedEngagements = [
SELECT Id, Name, Program__c, Program__r.Name
SELECT Id, Name, Program__c, Program__r.Name, Stage__c
FROM ProgramEngagement__c
WHERE Contact__c = :contactId
];

queriedEngagements.sort();
return Security.stripInaccessible(AccessType.READABLE, queriedEngagements)
.getRecords();
}
Expand Down
3 changes: 1 addition & 2 deletions force-app/main/default/classes/ProgramSelector.cls
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ public with sharing class ProgramSelector {
' IN :allowedProgramCohortStatuses'
);
}

programCohorts = Database.query(queryBuilder.buildSoqlQuery());

programCohorts.sort();
return Security.stripInaccessible(AccessType.READABLE, programCohorts)
.getRecords();
}
Expand Down
6 changes: 3 additions & 3 deletions force-app/main/default/classes/ServiceSelector.cls
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public with sharing class ServiceSelector {
return new List<Service__c>();
}
List<Service__c> queriedServices = [
SELECT Id, Name, Program__c
SELECT Id, Name, Program__c, Status__c
FROM Service__c
WHERE Program__c IN :programIds
];

queriedServices.sort();
return Security.stripInaccessible(AccessType.READABLE, queriedServices)
.getRecords();
}
Expand All @@ -40,7 +40,7 @@ public with sharing class ServiceSelector {
WHERE Id = :programEngagementId
)
];

services.sort();
return Security.stripInaccessible(AccessType.READABLE, services).getRecords();
}

Expand Down
100 changes: 91 additions & 9 deletions force-app/main/default/classes/ServiceService.cls
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,128 @@ public with sharing class ServiceService {
public ServiceService() {
}

private static final String SERVICE_STATUS_ACTIVE = 'ServiceStatusActive';
private static final String ENGAGEMENTS = 'engagements';
private static final String SERVICES = 'services';
private static final String LABEL = 'label';
private static final String VALUE = 'value';
private static final String NAME = 'Name';
private static final String Id = 'Id';
private static final String PROGRAM = 'program';
private static final String BSDT_ACTIVE_FILTER = 'BSDTActiveFilter';

@TestVisible
private FieldBucketSelector bucketSelector = new FieldBucketSelector();

@TestVisible
private FieldSetService fieldSetService = new FieldSetService();

@TestVisible
private ServiceSelector serviceSelector = new ServiceSelector();

@TestVisible
private ProgramEngagementService engagementService = new ProgramEngagementService();

@TestVisible
private ProgramEngagementSelector engagementSelector = new ProgramEngagementSelector();

@TestVisible
private Set<String> activeStatuses {
get {
if (activeStatuses == null) {
activeStatuses = getActiveStatuses();
}
return activeStatuses;
}
set;
}

private Set<String> getActiveStatuses() {
List<String> bucketNames = new List<String>{ SERVICE_STATUS_ACTIVE };
Set<String> activeStatuses = new Set<String>();

Schema.SObjectType serviceSObjType = Service__c.SObjectType;
Schema.SObjectField statusField = Service__c.Status__c;

for (
Bucket__mdt bucket : bucketSelector.getBuckets(
bucketNames,
serviceSObjType,
statusField
)
) {
for (BucketedValue__mdt value : bucket.BucketedValues__r) {
activeStatuses.add(value.Value__c);
}
}

return activeStatuses;
}

private Boolean isBsdtActiveFilterActive() {
List<FeatureGate__mdt> features = CustomMetadataSelector.getInstance()
.getAllFeatureGates();

for (FeatureGate__mdt feature : features) {
if (
feature.IsActive__c && BSDT_ACTIVE_FILTER.contains(feature.DeveloperName)
) {
return feature.IsActive__c;
}
}

return false;
}

public Map<String, List<Object>> getServicesEngagementsByContactId(Id contactId) {
Set<Id> programIds = new Set<Id>();
String serviceProgram = Schema.SObjectType.Service__c.Fields.Program__c.getName();
String engageProgram = Schema.SObjectType.ProgramEngagement__c.Fields.Program__c.getName();
Set<String> activeServiceStatuses = new Set<String>();
Set<String> activeProgramEngagementStages = new Set<String>();
Boolean bsdtFilterIsActive = isBsdtActiveFilterActive();

if (bsdtFilterIsActive) {
activeServiceStatuses = activeStatuses;
activeProgramEngagementStages = engagementService.getActiveStages();
}

Map<String, List<Object>> result = new Map<String, List<Object>>();
result.put('engagements', new List<Object>());
result.put('services', new List<Object>());
result.put(ENGAGEMENTS, new List<Object>());
result.put(SERVICES, new List<Object>());

for (
ProgramEngagement__c engagement : engagementSelector.getProgramEngagementsByContactId(
contactId
)
) {
programIds.add(engagement.Program__c);
result.get('engagements')
.add(convertObjectToOption(engagement, engageProgram));
if (
activeProgramEngagementStages.isEmpty() ||
activeProgramEngagementStages.contains(engagement.Stage__c)
) {
programIds.add(engagement.Program__c);
result.get(ENGAGEMENTS)
.add(convertObjectToOption(engagement, engageProgram));
}
}

for (Service__c service : serviceSelector.getServicesByProgramIds(programIds)) {
result.get('services').add(convertObjectToOption(service, serviceProgram));
if (
activeServiceStatuses.isEmpty() ||
activeServiceStatuses.contains(service.Status__c)
) {
result.get(SERVICES).add(convertObjectToOption(service, serviceProgram));
}
}

return result;
}

private Map<String, String> convertObjectToOption(sObject obj, String programField) {
Map<String, String> result = new Map<String, String>();
result.put('label', (String) obj.get('Name'));
result.put('value', (String) obj.get('Id'));
result.put('program', (String) obj.get(programField));
result.put(LABEL, (String) obj.get(NAME));
result.put(VALUE, (String) obj.get(ID));
result.put(PROGRAM, (String) obj.get(programField));
return result;
}

Expand Down
Loading

0 comments on commit bb5a983

Please sign in to comment.