Skip to content

Commit

Permalink
Merge pull request #190 from navikt/TOLK-2508
Browse files Browse the repository at this point in the history
TOLK-2508 - varsling til saksbehandler når det blir sendt inn nytt krav av en ikke-lesehjelp, og når bruker ikke har noen vedtak
  • Loading branch information
olsenrasmus authored Jun 6, 2024
2 parents 7f7f9ed + 401c0c5 commit 3079d05
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 2 deletions.
13 changes: 13 additions & 0 deletions force-app/main/default/classes/HOT_ClaimHandler.cls
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
public without sharing class HOT_ClaimHandler extends MyTriggers {
public override void onAfterInsert() {
List<Id> notifyNAVNotRegisteredReader = new List<Id>();

Set<Id> accountIds = new Set<Id>();
List<Id> claimIds = new List<Id>();
for (HOT_Claim__c claim : (List<HOT_Claim__c>) records) {
accountIds.add(claim.Claimant__c);
if(claim.IsLos__c==false){
notifyNAVNotRegisteredReader.add(claim.Id);
}
claimIds.add(claim.Id);
}
if (accountIds.size() > 0) {
// Call out to KRR through Queuable Apex
HOT_KRRAccountCalloutQueuable krr = new HOT_KRRAccountCalloutQueuable(accountIds);
System.enqueueJob(krr);
}
if (!claimIds.isEmpty()) {
HOT_ClaimNotificationService.NotifyNAVNoEntitlementOnUser(claimIds);
}
if (!notifyNAVNotRegisteredReader.isEmpty()) {
HOT_ClaimNotificationService.NotifyNAVNotRegisteredReader(notifyNAVNotRegisteredReader);
}
}
public override void onAfterUpdate(Map<Id, sObject> triggerOldMap) {
List<HOT_Claim__c> claimsToNotifyUserOnDeclinedStatus = new List<HOT_Claim__c>();
Expand Down
92 changes: 92 additions & 0 deletions force-app/main/default/classes/HOT_ClaimNotificationService.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
public without sharing class HOT_ClaimNotificationService {
@Future
public static void NotifyNAVNoEntitlementOnUser(List<Id> claimIds) {
List<HOT_Claim__c> claims = [
SELECT Id, Name, Account__c
FROM HOT_Claim__c
WHERE Id IN :claimIds
];
Set<Id> accountIds = new Set<Id>();
Map<Id, HOT_Claim__c> claimMap = new Map<Id, HOT_Claim__c>();
for(HOT_Claim__c claim : claims){
accountIds.add(claim.Account__c);
claimMap.put(claim.Account__c, claim);
}
List<HOT_Entitlement__c> entitlements = [
SELECT Id, Account__c
FROM HOT_Entitlement__c
WHERE Account__c IN :accountIds
];

Set<Id> entitledAccountIds = new Set<Id>();
for(HOT_Entitlement__c entitlement : entitlements){
entitledAccountIds.add(entitlement.Account__c);
}
List<User> navUsers =[SELECT Id FROM User WHERE Id in (SELECT userorgroupid from groupmember where group.name = 'HOT LOS Saksbehandler')];

for(Id accountId : accountIds){
if (!entitledAccountIds.contains(accountId)) {
HOT_Claim__c claim = claimMap.get(accountId);
if (claim != null) {
for(User user : navUsers){
Set<String> recipients = new Set<String>();
recipients.add(user.Id);
Messaging.CustomNotification notification = new Messaging.CustomNotification();
notification.setTitle('Lesehjelp har sendt inn krav på en bruker som ikke har noen vedtak');
notification.setBody('Legg på vedtak på brukeren');
notification.setNotificationTypeId(getCustomNotificationType('HOT_ClaimNotification').Id);
notification.setTargetId(claim.Id);
sendNotification(notification, recipients, (SObject) claim);
}
}
}
}
}

@Future
public static void NotifyNAVNotRegisteredReader(List<Id> claimIds) {
List<HOT_Claim__c> claims = [
SELECT Id, Name
FROM HOT_Claim__c
WHERE Id IN :claimIds
];
List<User> navUsers =[SELECT Id FROM User WHERE Id in (SELECT userorgroupid from groupmember where group.name = 'HOT LOS Saksbehandler')];

for(HOT_Claim__c claim : claims){
for(User user : navUsers){
Set<String> recipients = new Set<String>();
recipients.add(user.Id);
Messaging.CustomNotification notification = new Messaging.CustomNotification();
notification.setTitle('Lesehjelp uten ressursnummer');
notification.setBody('Lesehjelp uten ressursnummer har sendt inn et nytt krav');
notification.setNotificationTypeId(getCustomNotificationType('HOT_ClaimNotification').Id);
notification.setTargetId(claim.Id);
sendNotification(notification, recipients, (SObject) claim);
}
}
}
public static CustomNotificationType getCustomNotificationType(String devName) {
CustomNotificationType notificationType = [
SELECT Id, DeveloperName
FROM CustomNotificationType
WHERE DeveloperName = :devName
];
return notificationType;
}
public static void sendNotification(
Messaging.CustomNotification notification,
Set<String> recipients,
SObject record
) {
LoggerUtility logger = new LoggerUtility();

if (recipients != null && recipients.size() > 0) {
try {
notification.send(recipients);
} catch (Exception e) {
logger.exception(e, record, CRM_ApplicationDomain.Domain.HOT);
logger.publishSynch();
}
}
}
}
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>56.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ <h1 tabindex="0" class="typo-overskrift">Mine innsendte krav</h1>
>
<img class="navno-dekorator alertstripe__ikon" src={warningicon} alt="advarsel-ikon" />
<div class="typo-normal alertstripe__tekst">
Vi mangler kontaktinformasjon til personen du har vært lesehjelp for, som dermed da ikke
har fått beskjed om at du har sendt inn et nytt krav.
Vi mangler kontaktinformasjon til personen du har vært lesehjelp for, som da ikke har
fått beskjed om at du har sendt inn et nytt krav.
</div>
</div>
<div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<CustomNotificationType xmlns="http://soap.sforce.com/2006/04/metadata">
<customNotifTypeName>HOT_ClaimNotification</customNotifTypeName>
<desktop>true</desktop>
<masterLabel>HOT_ClaimNotification</masterLabel>
<mobile>false</mobile>
<slack>false</slack>
</CustomNotificationType>

0 comments on commit 3079d05

Please sign in to comment.