Skip to content

Commit 883e3e7

Browse files
committed
Bruk wrapper for å håndtere oppdateringene på samtalereferat
1 parent f242d7c commit 883e3e7

File tree

4 files changed

+65
-31
lines changed

4 files changed

+65
-31
lines changed

src/integration/henvendelse-cache/classes/domain/HenvendelseUpdateWrapper.cls

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
public with sharing class HenvendelseUpdateWrapper {
22
public Thread__c thread;
3+
public Conversation_Note__c convNote;
34
public Boolean isGeneralUpdate = false;
45
public Boolean isRedactionChange = false;
56
public Boolean isCloseThreadChange = false;

src/integration/henvendelse-cache/classes/handlers/ConvNoteCacheHandler.cls

+31-11
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
global class ConvNoteCacheHandler extends MyTriggers {
22
global override void onAfterInsert() {
3-
createHenvendelseCacheQueueable(
4-
(List<Conversation_Note__c>) records,
5-
false
6-
);
3+
List<HenvendelseUpdateWrapper> convNotes = new List<HenvendelseUpdateWrapper>();
4+
for (
5+
Conversation_Note__c record : (List<Conversation_Note__c>) records
6+
) {
7+
HenvendelseUpdateWrapper recordWrapper = new HenvendelseUpdateWrapper();
8+
recordWrapper.convNote = record;
9+
convNotes.add(recordWrapper);
10+
}
11+
12+
createHenvendelseCacheQueueable(convNotes);
713
}
814
global override void onAfterUpdate(Map<Id, SObject> triggerOldMap) {
915
List<String> fieldNamesToCheck = new List<String>{
@@ -17,7 +23,7 @@ global class ConvNoteCacheHandler extends MyTriggers {
1723
'CRM_Is_Redacted__c'
1824
};
1925

20-
List<Conversation_Note__c> convNotesWithRelevantChanges = new List<Conversation_Note__c>();
26+
List<HenvendelseUpdateWrapper> convNotesWithRelevantChanges = new List<HenvendelseUpdateWrapper>();
2127
for (
2228
Conversation_Note__c record : (List<Conversation_Note__c>) records
2329
) {
@@ -32,22 +38,36 @@ global class ConvNoteCacheHandler extends MyTriggers {
3238
recordOld
3339
)
3440
) {
35-
convNotesWithRelevantChanges.add(record);
41+
HenvendelseUpdateWrapper recordWrapper = new HenvendelseUpdateWrapper();
42+
recordWrapper.convNote = record;
43+
recordWrapper.isGeneralUpdate = true;
44+
convNotesWithRelevantChanges.add(recordWrapper);
45+
}
46+
47+
if (
48+
MyTriggers.hasChangedFields(
49+
new List<String>{ 'STO_Sensitive_Information__c' },
50+
record,
51+
recordOld
52+
)
53+
) {
54+
HenvendelseUpdateWrapper recordWrapper = new HenvendelseUpdateWrapper();
55+
recordWrapper.convNote = record;
56+
recordWrapper.isRedactionChange = true;
57+
convNotesWithRelevantChanges.add(recordWrapper);
3658
}
3759
}
3860
if (convNotesWithRelevantChanges.isEmpty()) {
3961
return;
4062
}
41-
createHenvendelseCacheQueueable(convNotesWithRelevantChanges, true);
63+
createHenvendelseCacheQueueable(convNotesWithRelevantChanges);
4264
}
4365

4466
private void createHenvendelseCacheQueueable(
45-
List<Conversation_Note__c> convNoteList,
46-
Boolean isUpdate
67+
List<HenvendelseUpdateWrapper> convNoteList
4768
) {
4869
Set<Id> recordIds = ConvNoteCacheFilterHelper.getRecordIdsRequiringCacheClear(
49-
convNoteList,
50-
isUpdate
70+
convNoteList
5171
);
5272
if (recordIds.isEmpty()) {
5373
return;

src/integration/henvendelse-cache/classes/helpers/ConvNoteCacheFilterHelper.cls

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
public with sharing class ConvNoteCacheFilterHelper {
22
public static Set<Id> getRecordIdsRequiringCacheClear(
3-
List<Conversation_Note__c> convNoteList,
4-
Boolean isUpdate
3+
List<HenvendelseUpdateWrapper> convNoteList
54
) {
65
ModiaIntegrationUser modiaIntegrationUser = new ModiaIntegrationUser();
76
Set<Id> recordIds = new Set<Id>();
8-
for (Conversation_Note__c convNote : convNoteList) {
7+
for (HenvendelseUpdateWrapper wrapper : convNoteList) {
98
//Only cache records created in Salesforce
109
if (
11-
convNote.LastModifiedById != modiaIntegrationUser.UserId ||
12-
(isUpdate && convNote.STO_Sensitive_Information__c == true) //Updates from Modia should be handled by the NAIS-app, except redaction requests
10+
wrapper.convNote.LastModifiedById !=
11+
modiaIntegrationUser.UserId ||
12+
wrapper.isRedactionChange //Updates from Modia should be handled by the NAIS-app, except redaction requests
1313
) {
14-
recordIds.add(convNote.Id);
14+
recordIds.add(wrapper.convNote.Id);
1515
}
1616
}
1717
return recordIds;

src/integration/henvendelse-cache/classes/helpers/tests/ConvNoteCacheFilterHelperTest.cls

+27-14
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,25 @@ public class ConvNoteCacheFilterHelperTest {
1313
)
1414
);
1515

16-
List<Conversation_Note__c> convNotes = [
16+
Conversation_Note__c convNote = [
1717
SELECT Id, LastModifiedById, STO_Sensitive_Information__c
1818
FROM Conversation_Note__c
1919
WHERE CRM_Henvendelse_BehandlingskjedeId__c = '123'
20+
LIMIT 1
2021
];
2122

23+
HenvendelseUpdateWrapper wrapper = new HenvendelseUpdateWrapper();
24+
wrapper.convNote = convNote;
25+
2226
Test.startTest();
2327
Set<Id> result = ConvNoteCacheFilterHelper.getRecordIdsRequiringCacheClear(
24-
convNotes,
25-
false //record is created
28+
new List<HenvendelseUpdateWrapper>{ wrapper }
2629
);
2730
Test.stopTest();
2831

2932
Assert.areEqual(1, result.size());
3033
Id actualRecordId = new List<Id>(result)[0];
31-
Assert.areEqual(convNotes[0].Id, actualRecordId);
34+
Assert.areEqual(convNote.Id, actualRecordId);
3235
}
3336

3437
@IsTest
@@ -61,16 +64,19 @@ public class ConvNoteCacheFilterHelperTest {
6164
);
6265
}
6366

64-
List<Conversation_Note__c> convNotes = [
67+
Conversation_Note__c convNote = [
6568
SELECT Id, LastModifiedById, STO_Sensitive_Information__c
6669
FROM Conversation_Note__c
6770
WHERE CRM_Henvendelse_BehandlingskjedeId__c = '789'
71+
LIMIT 1
6872
];
6973

74+
HenvendelseUpdateWrapper wrapper = new HenvendelseUpdateWrapper();
75+
wrapper.convNote = convNote;
76+
7077
Test.startTest();
7178
Set<Id> result = ConvNoteCacheFilterHelper.getRecordIdsRequiringCacheClear(
72-
convNotes,
73-
false //record is created
79+
new List<HenvendelseUpdateWrapper>{ wrapper }
7480
);
7581
Test.stopTest();
7682

@@ -107,24 +113,27 @@ public class ConvNoteCacheFilterHelperTest {
107113
);
108114
}
109115

110-
List<Conversation_Note__c> convNotes = [
116+
Conversation_Note__c convNote = [
111117
SELECT Id, LastModifiedById, STO_Sensitive_Information__c
112118
FROM Conversation_Note__c
113119
WHERE CRM_Henvendelse_BehandlingskjedeId__c = '789'
120+
LIMIT 1
114121
];
115122

123+
HenvendelseUpdateWrapper wrapper = new HenvendelseUpdateWrapper();
124+
wrapper.convNote = convNote;
125+
116126
Test.startTest();
117127
Set<Id> result = ConvNoteCacheFilterHelper.getRecordIdsRequiringCacheClear(
118-
convNotes,
119-
true //record is updated
128+
new List<HenvendelseUpdateWrapper>{ wrapper }
120129
);
121130
Test.stopTest();
122131

123132
Assert.areEqual(0, result.size());
124133
}
125134

126135
@IsTest
127-
static void shouldReturnOneRecordIdForConvNoteUpdatedByModiaIntegrationUserAndSensitiveInformationIsTrue() {
136+
static void shouldReturnOneRecordIdForRedactionReuestdByModiaIntegrationUser() {
128137
myTriggers.disable(ConvNoteCacheHandler.class);
129138

130139
Id profileId = [
@@ -154,16 +163,20 @@ public class ConvNoteCacheFilterHelperTest {
154163
);
155164
}
156165

157-
List<Conversation_Note__c> convNotes = [
166+
Conversation_Note__c convNote = [
158167
SELECT Id, LastModifiedById, STO_Sensitive_Information__c
159168
FROM Conversation_Note__c
160169
WHERE CRM_Henvendelse_BehandlingskjedeId__c = '789'
170+
LIMIT 1
161171
];
162172

173+
HenvendelseUpdateWrapper wrapper = new HenvendelseUpdateWrapper();
174+
wrapper.convNote = convNote;
175+
wrapper.isRedactionChange = true;
176+
163177
Test.startTest();
164178
Set<Id> result = ConvNoteCacheFilterHelper.getRecordIdsRequiringCacheClear(
165-
convNotes,
166-
true //record is updated
179+
new List<HenvendelseUpdateWrapper>{ wrapper }
167180
);
168181
Test.stopTest();
169182

0 commit comments

Comments
 (0)