Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor grant selector #53

Merged
merged 4 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
582 changes: 240 additions & 342 deletions force-app/main/default/classes/GGW_ApplicationCtrl.cls

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions force-app/main/default/classes/GGW_ApplicationCtrlTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public class GGW_ApplicationCtrlTest {
Test.stopTest();

System.assertEquals('MyTest Grant', app.Name, 'Grant name did not match');
System.assertEquals('Progress', app.Status__c, 'Initial grant status not set correctly to Progress');
System.assertEquals('In Progress', app.Status__c, 'Initial grant status not set correctly to In Progress');
// Check if all section are created for app
List<GGW_Selected_Item__c> selectedItems = [SELECT Id, Name, Grant_Application__c, GGW_Section__c, Sort_Order__c
FROM GGW_Selected_Item__c WHERE Grant_Application__c =:app.Id];
Expand Down Expand Up @@ -238,7 +238,7 @@ public class GGW_ApplicationCtrlTest {
// assertion checks happy path and set up
System.assertEquals(app.Id, appWrapper.recordid, 'No new grant was created');
System.assertEquals('Grant App',appWrapper.name, 'Default grant name did not match - Grant App');
System.assertEquals('Progress', appWrapper.status, 'Default grant status did not match expected - Progress');
System.assertEquals('In Progress', appWrapper.status, 'Default grant status did not match expected - In Progress');
// Check selected Items created as content blocks wraper to number of sections
System.assertEquals(sections.size(),appWrapper.selectedContentBlock.size(), 'The copy of created blocks from template did not match expected number');
}
Expand All @@ -253,7 +253,7 @@ public class GGW_ApplicationCtrlTest {
}
}
GGW_Grant_Application__c app = GGW_ApplicationCtrl.newGrant('MyTest Grant Sections', sections);
List<GGW_Selected_Item__c> selItemList = GGW_ApplicationCtrl.querySelectedItemsByGrant(app.Id);
List<GGW_Selected_Item__c> selItemList = GGW_SectionSelector.querySelectedItemsByGrant(app.Id);
//List<GGW_Selected_Item__c> selItemList = [SELECT Id, Name, GGW_Section__c,Grant_Application__c, Sort_Order__c
// FROM GGW_Selected_Item__c WHERE Grant_Application__c =:app.Id];
String itemid = selItemList[0].Id;
Expand All @@ -264,7 +264,7 @@ public class GGW_ApplicationCtrlTest {
GGW_ApplicationCtrl.saveSelectedSectionText(itemid, bwList[0].recordid);
Test.stopTest();
// assertion checks that item saved the Block text
List<GGW_Selected_Item__c> savedItemList = GGW_ApplicationCtrl.querySelectedItemsByGrant(app.Id);
List<GGW_Selected_Item__c> savedItemList = GGW_SectionSelector.querySelectedItemsByGrant(app.Id);
System.assertEquals(blocktext, savedItemList[0].Text_Block__c, 'Block text did not match template');
}
@isTest
Expand All @@ -278,7 +278,7 @@ public class GGW_ApplicationCtrlTest {
}
}
GGW_Grant_Application__c app = GGW_ApplicationCtrl.newGrant('Grant App Order', sections);
List<GGW_Selected_Item__c> selItemList = GGW_ApplicationCtrl.querySelectedItemsByGrant(app.Id);
List<GGW_Selected_Item__c> selItemList = GGW_SectionSelector.querySelectedItemsByGrant(app.Id);
// List of selected Iteam IDs - GGW_Selected_Item__c
List<String> itemList = new List<String>();
// FLip order first/last
Expand All @@ -293,7 +293,7 @@ public class GGW_ApplicationCtrlTest {
GGW_ApplicationCtrl.reorderSections(itemList, app.Id);
Test.stopTest();
// Check fliped order
List<GGW_Selected_Item__c> selOrderedList = GGW_ApplicationCtrl.querySelectedItemsByGrant(app.Id);
List<GGW_Selected_Item__c> selOrderedList = GGW_SectionSelector.querySelectedItemsByGrant(app.Id);
System.assertEquals(last, selOrderedList[0].Id, 'Last seleected section item did not match expected');
System.assertEquals(first, selOrderedList[selOrderedList.size()-1].Id, 'First seleectd section item did not match selected');
}
Expand Down
27 changes: 27 additions & 0 deletions force-app/main/default/classes/GGW_ApplicationSelector.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2022, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*
* GGW_ApplicationSelector SOQL Query class support GGW.
*
*/
public with sharing class GGW_ApplicationSelector {
public static List<GGW_Grant_Application__c> getGrantApplications(){
return [SELECT Id, Name, Application_Name__c, Logo_Download_Url__c,
DistributionPublicUrl__c, Status__c, Description__c,
Language__c, Include_Logo__c
FROM GGW_Grant_Application__c
WITH SECURITY_ENFORCED];
}

public static GGW_Grant_Application__c queryGrantApp(String appId){
return [SELECT Id, Name, Application_Name__c, Logo_Download_Url__c,
DistributionPublicUrl__c, Status__c, Description__c,
Language__c, Include_Logo__c
FROM GGW_Grant_Application__c
WHERE Id =: appId WITH SECURITY_ENFORCED LIMIT 1];
}

}
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>58.0</apiVersion>
<status>Active</status>
</ApexClass>
67 changes: 67 additions & 0 deletions force-app/main/default/classes/GGW_ApplicationSelectorTest.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* Copyright (c) 2022, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause

* This class contains unit tests for validating the behavior of Apex classes
* and triggers.
*
* Unit tests are class methods that verify whether a particular piece
* of code is working properly. Unit test methods take no arguments,
* commit no data to the database, and are flagged with the testMethod
* keyword in the method definition.
*
* All test methods in an org are executed whenever Apex code is deployed
* to a production org to confirm correctness, ensure code
* coverage, and prevent regressions. All Apex classes are
* required to have at least 75% code coverage in order to be deployed
* to a production org. In addition, all triggers must have some code coverage.
*
* The @isTest class annotation indicates this class only contains test
* methods. Classes defined with the @isTest annotation do not count against
* the org size limit for all Apex scripts.
*
* See the Apex Language Reference for more information about Testing and Code Coverage.
*/
@isTest
private class GGW_ApplicationSelectorTest {

@isTest
static void testQueryGrantApp(){
// Query all suggested sections
List<GGW_SectionWrapper> lst = GGW_ApplicationCtrl.getSections();
List<String> sections = new List<String>();
for (GGW_SectionWrapper gww : lst){
if(gww.selected){
sections.add(gww.recordid);
}
}
GGW_Grant_Application__c app = GGW_ApplicationCtrl.newGrant('Grant App', sections);

Test.startTest();
GGW_Grant_Application__c grant = GGW_ApplicationSelector.queryGrantApp(app.Id);
Test.stopTest();
System.assertEquals(grant.Name, 'Grant App', 'Could not create a new grant application');

}
@isTest
static void getGrantApplicationsTest(){
// Query all suggested sections
List<GGW_SectionWrapper> lst = GGW_ApplicationCtrl.getSections();
List<String> sections = new List<String>();
for (GGW_SectionWrapper gww : lst){
if(gww.selected){
sections.add(gww.recordid);
}
}
// Create 2 grants with same sections top test list
GGW_ApplicationCtrl.newGrant('Grant App 1', sections);
GGW_ApplicationCtrl.newGrant('Grant App 2', sections);

Test.startTest();
List<GGW_Grant_Application__c> grantList = GGW_ApplicationSelector.getGrantApplications();
Test.stopTest();
System.assertEquals(2, grantList.size(), 'Query grant application invalid');
}
}
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>58.0</apiVersion>
<status>Active</status>
</ApexClass>
32 changes: 32 additions & 0 deletions force-app/main/default/classes/GGW_ContentBlockSelector.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2022, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*
* GGW_ContentBlockSelector Salesforce Content Block text data selector class support GGW.
*
*/
public with sharing class GGW_ContentBlockSelector {
public static GGW_Content_Block__c queryContentBlockById(String blockid){
GGW_Content_Block__c cBlock = [SELECT Id, Name, Description__c
FROM GGW_Content_Block__c
WHERE Id =: blockid WITH SECURITY_ENFORCED LIMIT 1];
return cBlock;
}
public static List<GGW_Content_Block__c> queryContentBlocksBySection(String sectionId){
List<GGW_Content_Block__c> cbList = [SELECT Id, Name, Description__c, Short_Description__c,
Section__c, Section__r.Name, CreatedDate,
Language__c
FROM GGW_Content_Block__c
WHERE Section__c =: sectionId WITH SECURITY_ENFORCED];
return cbList;
}
public static List<GGW_Content_Block__c> queryContentBlocks(){
List<GGW_Content_Block__c> cbList = [SELECT Id, Name, Description__c, Short_Description__c,
Section__c, Section__r.Name, CreatedDate,
Language__c
FROM GGW_Content_Block__c WITH SECURITY_ENFORCED ORDER BY Section__c];
return cbList;
}
}
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>58.0</apiVersion>
<status>Active</status>
</ApexClass>
37 changes: 37 additions & 0 deletions force-app/main/default/classes/GGW_ContentSelector.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2022, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*
* GGW_ContentSelector Salesforce Content data selector class support GGW.
*
*/
public with sharing class GGW_ContentSelector {
public static ContentDocumentLink getDocLinkByLinkedEntity(String recordId) {
return [SELECT Id, LinkedEntityId, ContentDocumentId, IsDeleted, Visibility, ShareType
FROM ContentDocumentLink
WHERE LinkedEntityId =: recordId WITH SECURITY_ENFORCED LIMIT 1];
}
public static ContentDistribution getContentDistributionByDocId(String docId){
return [SELECT Id, Name, ContentVersionId, ContentDocumentId, RelatedRecordId, ContentDownloadUrl
FROM ContentDistribution
WHERE ContentDocumentId =: docId WITH SECURITY_ENFORCED LIMIT 1];
}

public static ContentDistribution getContentDistributionById(Id cdid){
ContentDistribution cdr = [SELECT Id, Name, ContentVersionId,
ContentDownloadUrl, DistributionPublicUrl
FROM ContentDistribution
WHERE Id =: cdid WITH SECURITY_ENFORCED LIMIT 1];
return cdr;
}
// Query ContentVersion by id
public static ContentVersion getContentFile(String cvid){
ContentVersion file = [SELECT Id, Title
FROM ContentVersion
WHERE Id =: cvid WITH SECURITY_ENFORCED];
return file;
}

}
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>58.0</apiVersion>
<status>Active</status>
</ApexClass>
2 changes: 1 addition & 1 deletion force-app/main/default/classes/GGW_ExportCtrl.cls
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public without sharing class GGW_ExportCtrl {
system.debug('### PDF VIew ID:'+this.recordId);
this.appName = 'This view requires a Grant record, missing.';
if(this.recordId != null && this.recordId.length() > 0){
GGW_Grant_Application__c app = GGW_Util.queryGrantApp(this.recordId.escapeHtml4());
GGW_Grant_Application__c app = GGW_ApplicationSelector.queryGrantApp(this.recordId.escapeHtml4());
if(app != null && app.Logo_Download_Url__c != null){
this.logoURL = app.Logo_Download_Url__c;
if(app.Include_Logo__c == true){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
*/
public class GGW_GrantApplicationWrapper {
@AuraEnabled public String recordid;
@AuraEnabled public String name;
@AuraEnabled public String name; // This can hold a Lookup standard records URL link to Grant by Name
@AuraEnabled public String textname; // Save only grant name as text
@AuraEnabled public String status;
@AuraEnabled public String logodisplayurl;
@AuraEnabled public Boolean logostate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class GGW_GrantApplicationWrapperTest {
Test.startTest();
GGW_GrantApplicationWrapper app = new GGW_GrantApplicationWrapper();
app.name = 'Test Grant';
app.status = 'Progress';
app.status = 'In Progress';
app.language = 'en_US';
app.logodisplayurl = 'https://grant.logo.org/logo.png';
app.unselectSectionList = GGW_ApplicationCtrl.getSections();
Expand Down
2 changes: 1 addition & 1 deletion force-app/main/default/classes/GGW_SampleData.cls
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public with sharing class GGW_SampleData {
List<GGW_Content_Block__c> lstBlock = [SELECT Id, Name, Section__c, Description__c, Short_Description__c FROM GGW_Content_Block__c WITH SECURITY_ENFORCED LIMIT 20];
GGW_Grant_Application__c gapp = new GGW_Grant_Application__c();
gapp.Name = 'Cloudy Grant Sample';
gapp.Status__c = 'Progress';
gapp.Status__c = 'In Progress';
gapp.Language__c = 'en_US';
if(Schema.sObjectType.GGW_Grant_Application__c.isCreateable()){
insert gapp;
Expand Down
59 changes: 59 additions & 0 deletions force-app/main/default/classes/GGW_SectionSelector.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2022, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*
* GGW_ContentSelector Grant Section data selector class support GGW.
*
*/
public with sharing class GGW_SectionSelector {
public static List<GGW_Selected_Item__c> querySelectedItemsByGrant(String appId){
List<GGW_Selected_Item__c> appItems = [SELECT Id, Application_Name__c, Grant_Application__c, GGW_Section__c,
Section_Name__c,Selected_Block__c, Sort_Order__c, Grant_Application__r.Status__c,
Selected_Block__r.Description__c, Text_Block__c, Language__c
FROM GGW_Selected_Item__c
WHERE Grant_Application__c =: appId WITH SECURITY_ENFORCED ORDER BY Sort_Order__c];
return appItems;
}

public static List<GGW_Section__c> querySectionsByLanguage(String lang){
List<GGW_Section__c> sectionList = [SELECT Id, Name, CreatedDate, Recommended__c, Suggested__c,
Sort_Order__c, Language__c
FROM GGW_Section__c
WHERE Suggested__c = true AND Language__c =: lang
WITH SECURITY_ENFORCED ORDER BY Sort_Order__c];
return sectionList;
}
public static List<GGW_Section__c> querySections(){
List<GGW_Section__c> sectionList = [SELECT Id, Name, CreatedDate, Recommended__c, Suggested__c,
Sort_Order__c, Language__c
FROM GGW_Section__c WITH SECURITY_ENFORCED ORDER BY Sort_Order__c];
return sectionList;
}
public static List<GGW_Section__c> querySectionsByName(String searchKey){
String key = '%' + searchKey + '%';
List<GGW_Section__c> sectionList = [SELECT Id, Name, CreatedDate, Recommended__c, Suggested__c,
Sort_Order__c, Language__c
FROM GGW_Section__c
WHERE Name LIKE :key AND Suggested__c = false
WITH SECURITY_ENFORCED ORDER BY Sort_Order__c LIMIT 20];
return sectionList;
}
// Return section with max order to add next section
public static GGW_Section__c findMaxOrderSection(){
List<GGW_Section__c> maxOrderList = [SELECT Sort_Order__c
FROM GGW_Section__c
WHERE Suggested__c = true WITH SECURITY_ENFORCED ORDER BY Sort_Order__c desc];
GGW_Section__c maxOrder = null;
// Handle situation when Sort order is null - TODO MAY be good to require it
for(GGW_Section__c section : maxOrderList ){
if(section.Sort_Order__c != null && section.Sort_Order__c > 0){
maxOrder = section; // assigned MAX order object first found END LOOP here
break; // EXIT Loop
}
}
return maxOrder;
}

}
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>58.0</apiVersion>
<status>Active</status>
</ApexClass>
6 changes: 0 additions & 6 deletions force-app/main/default/classes/GGW_Util.cls
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ public without sharing class GGW_Util {
WHERE Grant_Application__c =: appId WITH SECURITY_ENFORCED ORDER BY Sort_Order__c];
return items;
}
public static GGW_Grant_Application__c queryGrantApp(String appId){
return [SELECT Id, Name, Application_Name__c, Logo_Download_Url__c,
DistributionPublicUrl__c, Status__c, Description__c, Language__c, Include_Logo__c
FROM GGW_Grant_Application__c
WHERE Id =: appId WITH SECURITY_ENFORCED LIMIT 1];
}
public static Boolean isValidString(String str){
Boolean res = false;
if(str != null && str.length() > 0){
Expand Down
18 changes: 0 additions & 18 deletions force-app/main/default/classes/GGW_UtilTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -117,24 +117,6 @@ public class GGW_UtilTest {
Test.stopTest();
System.assertEquals(sections.size(), lstItems.size(), 'Grant app missing selected items');

}
@isTest
static void testQueryGrantApp(){
// Query all suggested sections
List<GGW_SectionWrapper> lst = GGW_ApplicationCtrl.getSections();
List<String> sections = new List<String>();
for (GGW_SectionWrapper gww : lst){
if(gww.selected){
sections.add(gww.recordid);
}
}
GGW_Grant_Application__c app = GGW_ApplicationCtrl.newGrant('Grant App', sections);

Test.startTest();
GGW_Grant_Application__c grant = GGW_Util.queryGrantApp(app.Id);
Test.stopTest();
System.assertEquals(grant.Name, 'Grant App', 'Could not create a new grant application');

}
@isTest
static void testSelectOptionFromPicklist(){
Expand Down
Loading