Skip to content

Commit 013da40

Browse files
authored
DFR-3915: Add NotificationRequestBuilder (#2528)
* Add NotificationRequestBuilder * Minor cleanup * Checkstyle errors
1 parent 48c2fb6 commit 013da40

File tree

10 files changed

+695
-3
lines changed

10 files changed

+695
-3
lines changed

src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/config/CourtDetails.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ public class CourtDetails {
1414
private String courtAddress;
1515
private String phoneNumber;
1616
private String email;
17+
private String emailReplyToId;
1718
}

src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/helper/ConsentedApplicationHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void setConsentVariationOrderLabelField(Map<String, Object> caseData) {
5959
}
6060
}
6161

62-
public Boolean isVariationOrder(final FinremCaseData caseData) {
62+
public boolean isVariationOrder(final FinremCaseData caseData) {
6363
List<NatureApplication> natureOfApplicationList = caseData.getNatureApplicationWrapper().getNatureOfApplication2();
6464
log.info("Nature list {}", natureOfApplicationList);
6565
return (!CollectionUtils.isEmpty(natureOfApplicationList)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package uk.gov.hmcts.reform.finrem.caseorchestration.mapper.notificationrequest;
2+
3+
import lombok.RequiredArgsConstructor;
4+
import org.springframework.stereotype.Component;
5+
6+
@Component
7+
@RequiredArgsConstructor
8+
class AbstractNotificationRequestMapper {
9+
10+
private final NotificationRequestBuilderFactory builderFactory;
11+
12+
/**
13+
* Creates a new instance of {@link NotificationRequestBuilder} to build
14+
* {@link uk.gov.hmcts.reform.finrem.caseorchestration.model.notification.NotificationRequest}.
15+
* @return a new instance of {@link NotificationRequestBuilder}
16+
*/
17+
protected NotificationRequestBuilder notificationRequestBuilder() {
18+
return builderFactory.newInstance();
19+
}
20+
}
Lines changed: 347 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,347 @@
1+
package uk.gov.hmcts.reform.finrem.caseorchestration.mapper.notificationrequest;
2+
3+
import lombok.RequiredArgsConstructor;
4+
import org.apache.commons.lang3.StringUtils;
5+
import org.springframework.context.annotation.Scope;
6+
import org.springframework.stereotype.Component;
7+
import uk.gov.hmcts.reform.finrem.caseorchestration.config.CourtDetailsConfiguration;
8+
import uk.gov.hmcts.reform.finrem.caseorchestration.helper.ConsentedApplicationHelper;
9+
import uk.gov.hmcts.reform.finrem.caseorchestration.helper.CourtHelper;
10+
import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.CaseType;
11+
import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.FinremCaseData;
12+
import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.FinremCaseDetails;
13+
import uk.gov.hmcts.reform.finrem.caseorchestration.model.notification.NotificationRequest;
14+
import uk.gov.hmcts.reform.finrem.caseorchestration.model.wrapper.SolicitorCaseDataKeysWrapper;
15+
import uk.gov.hmcts.reform.finrem.caseorchestration.notifications.service.EmailService;
16+
17+
import java.util.Objects;
18+
import java.util.Optional;
19+
20+
import static uk.gov.hmcts.reform.finrem.caseorchestration.OrchestrationConstants.CTSC_OPENING_HOURS;
21+
22+
@Component
23+
@Scope(value = "prototype")
24+
@RequiredArgsConstructor
25+
public class NotificationRequestBuilder {
26+
27+
private final CourtDetailsConfiguration courtDetailsConfiguration;
28+
private final ConsentedApplicationHelper consentedApplicationHelper;
29+
30+
private String caseReferenceNumber;
31+
private String solicitorReferenceNumber;
32+
private String divorceCaseNumber;
33+
private String name;
34+
private String notificationEmail;
35+
private String selectedCourt;
36+
private String caseType;
37+
private String generalEmailBody;
38+
private String phoneOpeningHours;
39+
private String caseOrderType;
40+
private String camelCaseOrderType;
41+
private String generalApplicationRejectionReason;
42+
private String applicantName;
43+
private String respondentName;
44+
private String barristerReferenceNumber;
45+
private String hearingType;
46+
private String intervenerSolicitorReferenceNumber;
47+
private String intervenerFullName;
48+
private String intervenerSolicitorFirm;
49+
private byte[] documentContents;
50+
private Boolean isNotDigital;
51+
private String hearingDate;
52+
private String judgeName;
53+
private String oldestDraftOrderDate;
54+
private String judgeFeedback;
55+
private String documentName;
56+
private String contactCourtName;
57+
private String contactCourtEmail;
58+
private String emailReplyToId;
59+
60+
/**
61+
* Sets default values for the NotificationRequestBuilder based on the provided case details.
62+
* This method sets the following fields:
63+
* <ul>
64+
* <li>applicantName</li>
65+
* <li>camelCaseOrderType</li>
66+
* <li>caseOrderType</li>
67+
* <li>caseReferenceNumber</li>
68+
* <li>caseType</li>
69+
* <li>contactCourtName</li>
70+
* <li>contactCourtEmail</li>
71+
* <li>divorceCaseNumber</li>
72+
* <li>emailReplyToId</li>
73+
* <li>phoneOpeningHours</li>
74+
* <li>respondentName</li>
75+
* <li>selectedCourt</li>
76+
* </ul>
77+
*
78+
* @param caseDetails the case details
79+
* @return the NotificationRequestBuilder instance with default values set
80+
*/
81+
public NotificationRequestBuilder withCaseDefaults(FinremCaseDetails caseDetails) {
82+
FinremCaseData caseData = caseDetails.getData();
83+
84+
caseReferenceNumber = String.valueOf(caseDetails.getId());
85+
applicantName = caseData.getFullApplicantName();
86+
caseType = CaseType.CONTESTED.equals(caseDetails.getCaseType()) ? EmailService.CONTESTED : EmailService.CONSENTED;
87+
divorceCaseNumber = caseData.getDivorceCaseNumber();
88+
phoneOpeningHours = CTSC_OPENING_HOURS;
89+
addSelectedCourtDetails(caseData);
90+
91+
if (caseData.isConsentedApplication()) {
92+
setConsentedDefaults(caseData);
93+
}
94+
95+
if (caseData.isContestedApplication()) {
96+
setContestedDefaults(caseDetails);
97+
}
98+
99+
return this;
100+
}
101+
102+
private void addSelectedCourtDetails(FinremCaseData caseData) {
103+
Optional.ofNullable(caseData.getSelectedAllocatedCourt())
104+
.map(courtDetailsConfiguration.getCourts()::get)
105+
.ifPresent(court -> {
106+
contactCourtName = court.getCourtName();
107+
contactCourtEmail = court.getEmail();
108+
emailReplyToId = court.getEmailReplyToId();
109+
});
110+
}
111+
112+
private void setContestedDefaults(FinremCaseDetails caseDetails) {
113+
respondentName = caseDetails.getData().getRespondentFullName();
114+
selectedCourt = CourtHelper.getSelectedFrc(caseDetails);
115+
}
116+
117+
private void setConsentedDefaults(FinremCaseData caseData) {
118+
respondentName = caseData.getFullRespondentNameConsented();
119+
120+
if (consentedApplicationHelper.isVariationOrder(caseData)) {
121+
caseOrderType = "variation";
122+
} else {
123+
caseOrderType = "consent";
124+
}
125+
camelCaseOrderType = StringUtils.capitalize(caseOrderType);
126+
}
127+
128+
/**
129+
* Sets the notification email destination to the court's email based on the selected allocated court in the case details.
130+
*
131+
* @param caseDetails the case details
132+
* @return the NotificationRequestBuilder instance
133+
*/
134+
public NotificationRequestBuilder withCourtAsEmailDestination(FinremCaseDetails caseDetails) {
135+
String selectedAllocatedCourt = caseDetails.getData().getSelectedAllocatedCourt();
136+
notificationEmail = courtDetailsConfiguration.getCourts().get(selectedAllocatedCourt).getEmail();
137+
138+
return this;
139+
}
140+
141+
/**
142+
* Sets solicitor-related fields in the NotificationRequestBuilder using the provided solicitor case data.
143+
* This method sets the following fields:
144+
* <ul>
145+
* <li>isNotDigital</li>
146+
* <li>name</li>
147+
* <li>notificationEmail</li>
148+
* <li>solicitorReferenceNumber</li>
149+
* </ul>
150+
*
151+
* @param solicitorCaseData the solicitor case data wrapper
152+
* @return the NotificationRequestBuilder instance with solicitor data set
153+
*/
154+
public NotificationRequestBuilder withSolicitorCaseData(SolicitorCaseDataKeysWrapper solicitorCaseData) {
155+
solicitorReferenceNumber = Objects.toString(solicitorCaseData.getSolicitorReferenceKey(), "");
156+
name = Objects.toString(solicitorCaseData.getSolicitorNameKey(), "");
157+
notificationEmail = Objects.toString(solicitorCaseData.getSolicitorEmailKey(), "");
158+
isNotDigital = solicitorCaseData.getSolicitorIsNotDigitalKey();
159+
160+
return this;
161+
}
162+
163+
/**
164+
* Builds a NotificationRequest object using the values set in the builder.
165+
*
166+
* @return a NotificationRequest
167+
*/
168+
public NotificationRequest build() {
169+
NotificationRequest notificationRequest = new NotificationRequest();
170+
notificationRequest.setCaseReferenceNumber(caseReferenceNumber);
171+
notificationRequest.setSolicitorReferenceNumber(solicitorReferenceNumber);
172+
notificationRequest.setDivorceCaseNumber(divorceCaseNumber);
173+
notificationRequest.setName(name);
174+
notificationRequest.setNotificationEmail(notificationEmail);
175+
notificationRequest.setSelectedCourt(selectedCourt);
176+
notificationRequest.setCaseType(caseType);
177+
notificationRequest.setGeneralEmailBody(generalEmailBody);
178+
notificationRequest.setPhoneOpeningHours(phoneOpeningHours);
179+
notificationRequest.setCaseOrderType(caseOrderType);
180+
notificationRequest.setCamelCaseOrderType(camelCaseOrderType);
181+
notificationRequest.setGeneralApplicationRejectionReason(generalApplicationRejectionReason);
182+
notificationRequest.setApplicantName(applicantName);
183+
notificationRequest.setRespondentName(respondentName);
184+
notificationRequest.setBarristerReferenceNumber(barristerReferenceNumber);
185+
notificationRequest.setHearingType(hearingType);
186+
notificationRequest.setIntervenerSolicitorReferenceNumber(intervenerSolicitorReferenceNumber);
187+
notificationRequest.setIntervenerFullName(intervenerFullName);
188+
notificationRequest.setIntervenerSolicitorFirm(intervenerSolicitorFirm);
189+
notificationRequest.setDocumentContents(documentContents);
190+
notificationRequest.setIsNotDigital(isNotDigital);
191+
notificationRequest.setHearingDate(hearingDate);
192+
notificationRequest.setJudgeName(judgeName);
193+
notificationRequest.setOldestDraftOrderDate(oldestDraftOrderDate);
194+
notificationRequest.setJudgeFeedback(judgeFeedback);
195+
notificationRequest.setDocumentName(documentName);
196+
notificationRequest.setContactCourtName(contactCourtName);
197+
notificationRequest.setContactCourtEmail(contactCourtEmail);
198+
notificationRequest.setEmailReplyToId(emailReplyToId);
199+
200+
return notificationRequest;
201+
}
202+
203+
public NotificationRequestBuilder caseReferenceNumber(String caseReferenceNumber) {
204+
this.caseReferenceNumber = caseReferenceNumber;
205+
return this;
206+
}
207+
208+
public NotificationRequestBuilder solicitorReferenceNumber(String solicitorReferenceNumber) {
209+
this.solicitorReferenceNumber = solicitorReferenceNumber;
210+
return this;
211+
}
212+
213+
public NotificationRequestBuilder divorceCaseNumber(String divorceCaseNumber) {
214+
this.divorceCaseNumber = divorceCaseNumber;
215+
return this;
216+
}
217+
218+
public NotificationRequestBuilder name(String name) {
219+
this.name = name;
220+
return this;
221+
}
222+
223+
public NotificationRequestBuilder notificationEmail(String notificationEmail) {
224+
this.notificationEmail = notificationEmail;
225+
return this;
226+
}
227+
228+
public NotificationRequestBuilder selectedCourt(String selectedCourt) {
229+
this.selectedCourt = selectedCourt;
230+
return this;
231+
}
232+
233+
public NotificationRequestBuilder caseType(String caseType) {
234+
this.caseType = caseType;
235+
return this;
236+
}
237+
238+
public NotificationRequestBuilder generalEmailBody(String generalEmailBody) {
239+
this.generalEmailBody = generalEmailBody;
240+
return this;
241+
}
242+
243+
public NotificationRequestBuilder phoneOpeningHours(String phoneOpeningHours) {
244+
this.phoneOpeningHours = phoneOpeningHours;
245+
return this;
246+
}
247+
248+
public NotificationRequestBuilder caseOrderType(String caseOrderType) {
249+
this.caseOrderType = caseOrderType;
250+
return this;
251+
}
252+
253+
public NotificationRequestBuilder camelCaseOrderType(String camelCaseOrderType) {
254+
this.camelCaseOrderType = camelCaseOrderType;
255+
return this;
256+
}
257+
258+
public NotificationRequestBuilder generalApplicationRejectionReason(String generalApplicationRejectionReason) {
259+
this.generalApplicationRejectionReason = generalApplicationRejectionReason;
260+
return this;
261+
}
262+
263+
public NotificationRequestBuilder applicantName(String applicantName) {
264+
this.applicantName = applicantName;
265+
return this;
266+
}
267+
268+
public NotificationRequestBuilder respondentName(String respondentName) {
269+
this.respondentName = respondentName;
270+
return this;
271+
}
272+
273+
public NotificationRequestBuilder barristerReferenceNumber(String barristerReferenceNumber) {
274+
this.barristerReferenceNumber = barristerReferenceNumber;
275+
return this;
276+
}
277+
278+
public NotificationRequestBuilder hearingType(String hearingType) {
279+
this.hearingType = hearingType;
280+
return this;
281+
}
282+
283+
public NotificationRequestBuilder intervenerSolicitorReferenceNumber(String intervenerSolicitorReferenceNumber) {
284+
this.intervenerSolicitorReferenceNumber = intervenerSolicitorReferenceNumber;
285+
return this;
286+
}
287+
288+
public NotificationRequestBuilder intervenerFullName(String intervenerFullName) {
289+
this.intervenerFullName = intervenerFullName;
290+
return this;
291+
}
292+
293+
public NotificationRequestBuilder intervenerSolicitorFirm(String intervenerSolicitorFirm) {
294+
this.intervenerSolicitorFirm = intervenerSolicitorFirm;
295+
return this;
296+
}
297+
298+
public NotificationRequestBuilder documentContents(byte[] documentContents) {
299+
this.documentContents = documentContents;
300+
return this;
301+
}
302+
303+
public NotificationRequestBuilder isNotDigital(Boolean isNotDigital) {
304+
this.isNotDigital = isNotDigital;
305+
return this;
306+
}
307+
308+
public NotificationRequestBuilder hearingDate(String hearingDate) {
309+
this.hearingDate = hearingDate;
310+
return this;
311+
}
312+
313+
public NotificationRequestBuilder judgeName(String judgeName) {
314+
this.judgeName = judgeName;
315+
return this;
316+
}
317+
318+
public NotificationRequestBuilder oldestDraftOrderDate(String oldestDraftOrderDate) {
319+
this.oldestDraftOrderDate = oldestDraftOrderDate;
320+
return this;
321+
}
322+
323+
public NotificationRequestBuilder judgeFeedback(String judgeFeedback) {
324+
this.judgeFeedback = judgeFeedback;
325+
return this;
326+
}
327+
328+
public NotificationRequestBuilder documentName(String documentName) {
329+
this.documentName = documentName;
330+
return this;
331+
}
332+
333+
public NotificationRequestBuilder contactCourtName(String contactCourtName) {
334+
this.contactCourtName = contactCourtName;
335+
return this;
336+
}
337+
338+
public NotificationRequestBuilder contactCourtEmail(String contactCourtEmail) {
339+
this.contactCourtEmail = contactCourtEmail;
340+
return this;
341+
}
342+
343+
public NotificationRequestBuilder emailReplyToId(String emailReplyToId) {
344+
this.emailReplyToId = emailReplyToId;
345+
return this;
346+
}
347+
}

0 commit comments

Comments
 (0)