From bcc39dcdd768ebfaa70ee5f431b51ec9f21b3966 Mon Sep 17 00:00:00 2001 From: Tom Saunders Date: Mon, 9 Dec 2024 09:09:35 +0000 Subject: [PATCH] Make exec applying notif service thread safe. --- .../ExecutorsApplyingNotificationService.java | 53 ++++++++++++------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/probate/service/ExecutorsApplyingNotificationService.java b/src/main/java/uk/gov/hmcts/probate/service/ExecutorsApplyingNotificationService.java index bf382d04e5..d4bed484cd 100644 --- a/src/main/java/uk/gov/hmcts/probate/service/ExecutorsApplyingNotificationService.java +++ b/src/main/java/uk/gov/hmcts/probate/service/ExecutorsApplyingNotificationService.java @@ -18,10 +18,8 @@ @Service public class ExecutorsApplyingNotificationService { - private List> executorList; - public List> createExecutorList(CaseData caseData) { - executorList = new ArrayList<>(); + List> executorList = new ArrayList<>(); if (caseData.getExecutorsApplyingNotifications() != null) { if (!caseData.getExecutorsApplyingNotifications().isEmpty()) { caseData.getExecutorsApplyingNotifications().clear(); @@ -29,44 +27,61 @@ public List> createExecutorList( } if (caseData.getApplicationType().equals(ApplicationType.PERSONAL)) { - addPrimaryApplicant(caseData); - addAdditionalExecutors(caseData); + addPrimaryApplicant(caseData, executorList); + addAdditionalExecutors(caseData, executorList); } else { - addSolicitor(caseData); + addSolicitor(caseData, executorList); } return executorList; } - private void addAdditionalExecutors(CaseData caseData) { + private void addAdditionalExecutors( + final CaseData caseData, + final List> executorList) { if (caseData.getAdditionalExecutorsApplying() != null) { for (CollectionMember executorApplying : caseData .getAdditionalExecutorsApplying()) { - executorList.add(buildExecutorList(executorApplying.getValue().getApplyingExecutorName(), - executorApplying.getValue().getApplyingExecutorEmail(), - executorApplying.getValue().getApplyingExecutorAddress())); + executorList.add(buildExecutorList( + executorApplying.getValue().getApplyingExecutorName(), + executorApplying.getValue().getApplyingExecutorEmail(), + executorApplying.getValue().getApplyingExecutorAddress(), + executorList.size())); } } } - private void addPrimaryApplicant(CaseData caseData) { + private void addPrimaryApplicant( + final CaseData caseData, + final List> executorList) { if (YES.equals(caseData.getPrimaryApplicantIsApplying()) || caseData.getPrimaryApplicantIsApplying() == null) { - executorList.add(buildExecutorList(caseData.getPrimaryApplicantFullName(), - caseData.getPrimaryApplicantEmailAddress(), caseData.getPrimaryApplicantAddress())); + executorList.add(buildExecutorList( + caseData.getPrimaryApplicantFullName(), + caseData.getPrimaryApplicantEmailAddress(), + caseData.getPrimaryApplicantAddress(), + executorList.size())); } } - private void addSolicitor(CaseData caseData) { - executorList.add(buildExecutorList(caseData.getSolsSOTName(), - caseData.getSolsSolicitorEmail(), caseData.getSolsSolicitorAddress())); + private void addSolicitor( + final CaseData caseData, + final List> executorList) { + executorList.add(buildExecutorList( + caseData.getSolsSOTName(), + caseData.getSolsSolicitorEmail(), + caseData.getSolsSolicitorAddress(), + executorList.size())); } - private CollectionMember buildExecutorList(String name, String email, - SolsAddress address) { - return new CollectionMember<>(String.valueOf(executorList.size() + 1), ExecutorsApplyingNotification.builder() + private CollectionMember buildExecutorList( + final String name, + final String email, + final SolsAddress address, + final int execListSize) { + return new CollectionMember<>(String.valueOf(execListSize + 1), ExecutorsApplyingNotification.builder() .name(name) .email(email) .address(address)