Skip to content

Commit

Permalink
Merge pull request #270 from navikt/Snokelogg
Browse files Browse the repository at this point in the history
Legger på snokelogg på lesekrav, lesekravlinje, og vedtak
  • Loading branch information
olsenrasmus authored Dec 11, 2024

Verified

This commit was signed with the committer’s verified signature. The key has expired.
renovate-bot Mend Renovate
2 parents fdf4b74 + 3438030 commit 6e3f293
Showing 4 changed files with 232 additions and 0 deletions.
108 changes: 108 additions & 0 deletions force-app/main/eventMonitoring/classes/HOT_LosUriEventService.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
convert UriEvent to Log__c record with lookup to Person Ident
Make it possible for NAV's "snokelogg" to get log elemnts
*/
public with sharing class HOT_LosUriEventService {
public static void addPersonRelatedRecordsToLog(List<UriEvent> uriEvents) {
List<Log__c> logs = new List<Log__c>();

Map<Id, UriEvent> uriEventByRecordId = new Map<Id, UriEvent>();

//record ids for each object we want to log
Set<Id> hotClaimRecordIds = new Set<Id>();
Set<Id> hotClaimLineItemsRecordIds = new Set<Id>();
Set<Id> hotEntitlementRecordIds = new Set<Id>();

//check if object type should be logged
for (UriEvent ue : uriEvents) {
//only standard users are logged
if (ue.UserType != 'Standard')
continue;

switch on ue.QueriedEntities {
when 'HOT_Claim__c' {
uriEventByRecordId.put(ue.RecordId, ue);
hotClaimRecordIds.add(ue.RecordId);
}
when 'HOT_ClaimLineItem__c' {
uriEventByRecordId.put(ue.RecordId, ue);
hotClaimLineItemsRecordIds.add(ue.RecordId);
}
when 'HOT_Entitlement__c' {
uriEventByRecordId.put(ue.RecordId, ue);
hotEntitlementRecordIds.add(ue.RecordId);
}
}
}

//get related person ident for each object
Map<Id, String> personIdentByRecordId = getPersonIdentsForEachObject(
hotClaimRecordIds,
hotClaimLineItemsRecordIds,
hotEntitlementRecordIds
);

//add log elemnt with person ident
for (Id recordId : personIdentByRecordId.keyset()) {
logs.add(addLogElement(uriEventByRecordId.get(recordId), personIdentByRecordId.get(recordId)));
}

if (logs.size() > 0) {
insert logs;
}
}

private static Map<Id, String> getPersonIdentsForEachObject(
Set<Id> hotClaimRecordIds,
Set<Id> hotClaimLineItemsRecordIds,
Set<Id> hotEntitlementRecordIds
) {
Map<Id, String> personIdentByRecordId = new Map<Id, String>();

//HOT Claim
if (hotClaimRecordIds.size() > 0) {
for (HOT_Claim__c claim : [
SELECT Id, Claimant__r.CRM_Person__r.Name
FROM HOT_Claim__c
WHERE Id IN :hotClaimRecordIds
]) {
personIdentByRecordId.put(claim.Id, claim.Claimant__r.CRM_Person__r.Name);
}
}
//HOT ClaimLineItem
if (hotClaimLineItemsRecordIds.size() > 0) {
for (HOT_ClaimLineItem__c claimLineItem : [
SELECT Id, Claim__r.Claimant__r.CRM_Person__r.Name
FROM HOT_ClaimLineItem__c
WHERE Id IN :hotClaimLineItemsRecordIds
]) {
personIdentByRecordId.put(claimLineItem.Id, claimLineItem.Claim__r.Claimant__r.CRM_Person__r.Name);
}
}
//HOT Entitlement
if (hotEntitlementRecordIds.size() > 0) {
for (HOT_Entitlement__c entitlement : [
SELECT Id, Account__r.CRM_Person__r.Name
FROM HOT_Entitlement__c
WHERE Id IN :hotEntitlementRecordIds
]) {
personIdentByRecordId.put(entitlement.Id, entitlement.Account__r.CRM_Person__r.Name);
}
}

return personIdentByRecordId;
}

private static Log__c addLogElement(UriEvent ue, String personIdent) {
return new Log__c(
CRM_RecordId__c = ue.RecordId,
CRM_EventDate__c = ue.EventDate,
CRM_QueriedEntity__c = ue.QueriedEntities,
CRM_Username__c = ue.Username,
CRM_Operation__c = ue.Operation,
CRM_PersonIdent__c = personIdent,
CRM_Type__c = 'LightningUriEvent',
CRM_Status__c = 'Completed'
);
}
}
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>
114 changes: 114 additions & 0 deletions force-app/main/eventMonitoring/classes/HOT_LosUriEventServiceTest.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
@IsTest
private class HOT_LosUriEventServiceTest {
@TestSetup
static void makeData() {
Account acc = new Account();
acc.Name = 'Ola Lesehjelp';
insert acc;
Account acc2 = new Account();
acc2.INT_PersonIdent__c = '01010101010';
acc2.Name = 'Kari Bruker';
acc2.INT_KrrMobilePhone__c = '12345678';
insert acc2;
HOT_Claim__c claim = HOT_LesehjelpTestDataFactory.createClaim(acc2, acc);
claim.UserPersonNumber__c = '01010101010';
insert claim;
HOT_ClaimLineItem__c cli = HOT_LesehjelpTestDataFactory.createClaimLineItems(claim);
insert cli;
HOT_Entitlement__c entitlement = HOT_LesehjelpTestDataFactory.createEntitlement(acc2);
insert entitlement;
}

@IsTest
private static void addPersonRelatedRecordsToLog_forHotClaim() {
HOT_Claim__c claim = [
SELECT Id, Claimant__c, Claimant__r.CRM_Person__r.Name
FROM HOT_Claim__c
LIMIT 1
];

List<UriEvent> uriEvents = new List<UriEvent>();
uriEvents.add(new UriEvent(claim.Id, DateTime.now(), 'HOT_Claim__c', 'Read', '[email protected]', 'Standard'));

Test.startTest();
HOT_LosUriEventService.addPersonRelatedRecordsToLog(uriEvents);
Test.stopTest();

List<Log__c> logs = [
SELECT CRM_PersonIdent__c
FROM Log__c
WHERE CRM_Type__c = 'LightningUriEvent' AND CRM_QueriedEntity__c = 'HOT_Claim__c'
];
System.assertEquals(1, logs.size(), 'One log element is created');
System.assertEquals(
claim.Claimant__r.CRM_Person__r.Name,
logs[0].CRM_PersonIdent__c,
'Log element should have persons fødselsr / dnr'
);
}
@IsTest
private static void addPersonRelatedRecordsToLog_forHotClaimLineItem() {
HOT_ClaimLineItem__c claimLineItem = [
SELECT Id, Claim__r.Claimant__r.CRM_Person__r.Name
FROM HOT_ClaimLineItem__c
LIMIT 1
];

List<UriEvent> uriEvents = new List<UriEvent>();
uriEvents.add(
new UriEvent(
claimLineItem.Id,
DateTime.now(),
'HOT_ClaimLineItem__c',
'Read',
'[email protected]',
'Standard'
)
);

Test.startTest();
HOT_LosUriEventService.addPersonRelatedRecordsToLog(uriEvents);
Test.stopTest();

List<Log__c> logs = [
SELECT CRM_PersonIdent__c
FROM Log__c
WHERE CRM_Type__c = 'LightningUriEvent' AND CRM_QueriedEntity__c = 'HOT_ClaimLineItem__c'
];
System.assertEquals(1, logs.size(), 'One log element is created');
System.assertEquals(
claimLineItem.Claim__r.Claimant__r.CRM_Person__r.Name,
logs[0].CRM_PersonIdent__c,
'Log element should have persons fødselsr / dnr'
);
}
@IsTest
private static void addPersonRelatedRecordsToLog_forHotEntitlement() {
HOT_Entitlement__c entitlement = [
SELECT Id, Account__r.CRM_Person__r.Name
FROM HOT_Entitlement__c
LIMIT 1
];

List<UriEvent> uriEvents = new List<UriEvent>();
uriEvents.add(
new UriEvent(entitlement.Id, DateTime.now(), 'HOT_Entitlement__c', 'Read', '[email protected]', 'Standard')
);

Test.startTest();
HOT_LosUriEventService.addPersonRelatedRecordsToLog(uriEvents);
Test.stopTest();

List<Log__c> logs = [
SELECT CRM_PersonIdent__c
FROM Log__c
WHERE CRM_Type__c = 'LightningUriEvent' AND CRM_QueriedEntity__c = 'HOT_Entitlement__c'
];
System.assertEquals(1, logs.size(), 'One log element is created');
System.assertEquals(
entitlement.Account__r.CRM_Person__r.Name,
logs[0].CRM_PersonIdent__c,
'Log element should have persons fødselsr / dnr'
);
}
}
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>

0 comments on commit 6e3f293

Please sign in to comment.