Skip to content

Commit

Permalink
Make exec applying notif service thread safe.
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-saunders-cts committed Dec 9, 2024
1 parent 89fccf3 commit bcc39dc
Showing 1 changed file with 34 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,55 +18,70 @@
@Service
public class ExecutorsApplyingNotificationService {

private List<CollectionMember<ExecutorsApplyingNotification>> executorList;

public List<CollectionMember<ExecutorsApplyingNotification>> createExecutorList(CaseData caseData) {
executorList = new ArrayList<>();
List<CollectionMember<ExecutorsApplyingNotification>> executorList = new ArrayList<>();
if (caseData.getExecutorsApplyingNotifications() != null) {
if (!caseData.getExecutorsApplyingNotifications().isEmpty()) {
caseData.getExecutorsApplyingNotifications().clear();
}
}

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<CollectionMember<ExecutorsApplyingNotification>> executorList) {
if (caseData.getAdditionalExecutorsApplying() != null) {
for (CollectionMember<AdditionalExecutorApplying> 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<CollectionMember<ExecutorsApplyingNotification>> 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<CollectionMember<ExecutorsApplyingNotification>> executorList) {
executorList.add(buildExecutorList(
caseData.getSolsSOTName(),
caseData.getSolsSolicitorEmail(),
caseData.getSolsSolicitorAddress(),
executorList.size()));

}

private CollectionMember<ExecutorsApplyingNotification> buildExecutorList(String name, String email,
SolsAddress address) {
return new CollectionMember<>(String.valueOf(executorList.size() + 1), ExecutorsApplyingNotification.builder()
private CollectionMember<ExecutorsApplyingNotification> 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)
Expand Down

0 comments on commit bcc39dc

Please sign in to comment.