generated from navikt/crm-shared-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #173 from navikt/Person-highlight-panel
Person highlight panel
- Loading branch information
Showing
24 changed files
with
1,158 additions
and
145 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
force-app/main/default/classes/HOT_PersonAccessBadgesController.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
public without sharing class HOT_PersonAccessBadgesController { | ||
/** | ||
* @description Get an apex type holding all the data we need for showing badges. | ||
*/ | ||
@AuraEnabled(cacheable=true) | ||
public static List<AccessBadge> getPersonAccessBadges(String field, String parentObject, String parentRecordId) { | ||
Id personId = getPersonId(field, parentObject, parentRecordId); | ||
|
||
if (String.isBlank(personId)) { | ||
return new List<AccessBadge>(); | ||
} | ||
|
||
Person__c person = getPerson(personId); | ||
return createAccessBadgeList(person); | ||
} | ||
|
||
private static List<AccessBadge> createAccessBadgeList(Person__c person) { | ||
List<AccessBadge> accessBadgeList = new List<AccessBadge>(); | ||
// Add INT_IsNavEmployee__c | ||
if (person.INT_IsNavEmployee__c) { | ||
accessBadgeList.add(new AccessBadge('isNavEmployee', 'Skjermet person (Nav Ansatt)')); | ||
} | ||
|
||
// Add INT_Confidential__c | ||
// prettier-ignore | ||
if (true == person.INT_Confidential__c.equalsIgnoreCase('FORTROLIG')) { | ||
accessBadgeList.add(new AccessBadge('isConfidential', 'Skjermet adresse - fortrolig')); | ||
} else if (true == person.INT_Confidential__c.equalsIgnoreCase('STRENGT_FORTROLIG')) { | ||
accessBadgeList.add(new AccessBadge('isConfidential', 'Skjermet adresse - strengt fortrolig')); | ||
} else if ( | ||
true == person.INT_Confidential__c.equalsIgnoreCase('STRENGT_FORTROLIG_UTLAND') | ||
) { | ||
accessBadgeList.add(new AccessBadge('isConfidential', 'Skjermet adresse - strengt fortrolig')); | ||
} | ||
return accessBadgeList; | ||
} | ||
|
||
/** | ||
* @description Dynamically find the person ID | ||
* *Example | ||
* - field = 'Account.CRM_Person__c'; | ||
* - objString = 'Case'; | ||
* - recordId = '5001X000007xMSuQAM'; | ||
* - relation = 'Id'; | ||
*/ | ||
private static Id getPersonId(String field, String parentObject, String parentRecordId) { | ||
Id personId = null; | ||
String queryString = 'SELECT ' + field + ' FROM ' + parentObject + ' WHERE Id = :parentRecordId LIMIT 1'; | ||
List<SObject> objList = Database.query(String.escapeSingleQuotes(queryString)); | ||
|
||
if (false == objList.isEmpty()) { | ||
personId = (Id) getFieldValue(objList[0], field); | ||
} | ||
|
||
return personId; | ||
} | ||
|
||
/** | ||
* @description recursive method for collecting the value of a field on a sObject | ||
*/ | ||
private static Object getFieldValue(SObject obj, String fieldName) { | ||
if (obj == null) { | ||
return null; | ||
} | ||
List<String> fieldNameList = fieldName.split('\\.'); | ||
|
||
if (1 < fieldNameList.size()) { | ||
return getFieldValue(obj.getSObject(fieldNameList.remove(0)), String.join(fieldNameList, '.')); | ||
} | ||
|
||
return obj.get(fieldNameList[0]); | ||
} | ||
|
||
private static Person__c getPerson(Id personId) { | ||
List<Person__c> personList = [ | ||
SELECT Id, INT_Confidential__c, INT_IsNavEmployee__c | ||
FROM Person__c | ||
WHERE Id = :personId | ||
]; | ||
|
||
return personList.isEmpty() ? null : personList[0]; | ||
} | ||
|
||
public class AccessBadge { | ||
@AuraEnabled | ||
public String name; | ||
@AuraEnabled | ||
public String label; | ||
|
||
public AccessBadge(String name, String label) { | ||
this.name = name; | ||
this.label = label; | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
force-app/main/default/classes/HOT_PersonAccessBadgesController.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>62.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
109 changes: 109 additions & 0 deletions
109
force-app/main/default/classes/HOT_PersonAccessBadgesControllerTest.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
@IsTest | ||
private inherited sharing class HOT_PersonAccessBadgesControllerTest { | ||
@IsTest | ||
static void getPersonAccessBadgesNavEmployee() { | ||
Person__c p = (Person__c) HOT_ST_TestDataFactory.createRecord( | ||
new Person__c( | ||
INT_ActorId__c = '100003000120', | ||
INT_Confidential__c = 'UGRADERT', | ||
INT_FirstName__c = 'Harry', | ||
INT_IsNavEmployee__c = true, | ||
INT_LastName__c = 'Potter' | ||
), | ||
true | ||
); | ||
|
||
p = [SELECT Id, CRM_Account__c FROM Person__c WHERE Id = :p.Id]; | ||
|
||
List<HOT_PersonAccessBadgesController.AccessBadge> result; | ||
|
||
Test.startTest(); | ||
result = HOT_PersonAccessBadgesController.getPersonAccessBadges('CRM_Person__c', 'Account', p.CRM_Account__c); | ||
Test.stopTest(); | ||
|
||
System.assertEquals(1, result.size(), 'Expected one result'); | ||
} | ||
|
||
@IsTest | ||
static void getPersonAccessBadgesFORTROLIG() { | ||
Person__c p = (Person__c) HOT_ST_TestDataFactory.createRecord( | ||
new Person__c( | ||
INT_ActorId__c = '100003000120', | ||
INT_Confidential__c = 'FORTROLIG', | ||
INT_FirstName__c = 'Harry', | ||
INT_IsNavEmployee__c = false, | ||
INT_LastName__c = 'Potter' | ||
), | ||
true | ||
); | ||
|
||
p = [SELECT Id, CRM_Account__c FROM Person__c WHERE Id = :p.Id]; | ||
|
||
List<HOT_PersonAccessBadgesController.AccessBadge> result; | ||
|
||
Test.startTest(); | ||
result = HOT_PersonAccessBadgesController.getPersonAccessBadges('CRM_Person__c', 'Account', p.CRM_Account__c); | ||
Test.stopTest(); | ||
|
||
System.assertEquals(1, result.size(), 'Expected one result'); | ||
System.assertEquals('Skjermet adresse - fortrolig', result[0].label, 'Expected Skjermet adresse - fortrolig'); | ||
} | ||
|
||
@IsTest | ||
static void getPersonAccessBadgesSTRENGT_FORTROLIG() { | ||
Person__c p = (Person__c) HOT_ST_TestDataFactory.createRecord( | ||
new Person__c( | ||
INT_ActorId__c = '100003000120', | ||
INT_Confidential__c = 'STRENGT_FORTROLIG', | ||
INT_FirstName__c = 'Harry', | ||
INT_IsNavEmployee__c = false, | ||
INT_LastName__c = 'Potter' | ||
), | ||
true | ||
); | ||
|
||
p = [SELECT Id, CRM_Account__c FROM Person__c WHERE Id = :p.Id]; | ||
|
||
List<HOT_PersonAccessBadgesController.AccessBadge> result; | ||
|
||
Test.startTest(); | ||
result = HOT_PersonAccessBadgesController.getPersonAccessBadges('CRM_Person__c', 'Account', p.CRM_Account__c); | ||
Test.stopTest(); | ||
|
||
System.assertEquals(1, result.size(), 'Expected one result'); | ||
System.assertEquals( | ||
'Skjermet adresse - strengt fortrolig', | ||
result[0].label, | ||
'Expected Skjermet adresse - strengt fortrolig' | ||
); | ||
} | ||
|
||
@IsTest | ||
static void getPersonAccessBadgesSTRENGT_FORTROLIG_UTLAND() { | ||
Person__c p = (Person__c) HOT_ST_TestDataFactory.createRecord( | ||
new Person__c( | ||
INT_ActorId__c = '100003000120', | ||
INT_Confidential__c = 'STRENGT_FORTROLIG_UTLAND', | ||
INT_FirstName__c = 'Harry', | ||
INT_IsNavEmployee__c = false, | ||
INT_LastName__c = 'Potter' | ||
), | ||
true | ||
); | ||
|
||
p = [SELECT Id, CRM_Account__c FROM Person__c WHERE Id = :p.Id]; | ||
|
||
List<HOT_PersonAccessBadgesController.AccessBadge> result; | ||
|
||
Test.startTest(); | ||
result = HOT_PersonAccessBadgesController.getPersonAccessBadges('CRM_Person__c', 'Account', p.CRM_Account__c); | ||
Test.stopTest(); | ||
|
||
System.assertEquals(1, result.size(), 'Expected one result'); | ||
System.assertEquals( | ||
'Skjermet adresse - strengt fortrolig', | ||
result[0].label, | ||
'Expected Skjermet adresse - strengt fortrolig' | ||
); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
force-app/main/default/classes/HOT_PersonAccessBadgesControllerTest.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>62.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.