Skip to content

Commit

Permalink
Merge branch 'main' into feat/FSADT1-1193
Browse files Browse the repository at this point in the history
  • Loading branch information
paulushcgcj authored Feb 15, 2024
2 parents d661139 + 1998a1a commit 5fa147a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ create table if not exists nrfc.email_log (
exception_message text null,
template_name varchar(40) not null,
email_address varchar(100) not null,
email_subject varchar(50) not null,
email_subject varchar(100) not null,
email_variables JSONB null,
create_timestamp timestamp default current_timestamp not null,
update_timestamp timestamp default current_timestamp,
Expand Down
2 changes: 1 addition & 1 deletion backend/src/main/resources/templates/revision.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<#include "emailLogo.html">

<p>
Client Admin,
Dear ${business.districtName},
</p>
<div>&nbsp;</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,71 +59,57 @@ public Mono<MessagingWrapper<SubmissionInformationDto>> loadSubmissionDetails(
);
}

public Mono<EmailRequestDto> buildMailMessage(
MessagingWrapper<Integer> message
) {

public Mono<EmailRequestDto> buildMailMessage(MessagingWrapper<Integer> message) {
if (message
.parameters()
.get(ApplicationConstant.SUBMISSION_STATUS) == null
) {
.parameters()
.get(ApplicationConstant.SUBMISSION_STATUS) == null
) {
return Mono.empty();
}

return
submissionDetailRepository
return submissionDetailRepository
.findBySubmissionId(message.payload())
.doOnNext(
submission -> log.info("Loaded submission details for mail purpose {}", submission)
)
.flatMap(details ->
contactRepository
.findFirstBySubmissionId(message.payload())
.doOnNext(submissionContact -> log.info(
"Loaded submission contact details for mail purpose {}", submissionContact)
)
// Reads the district information from the forest client district endpoint if is a client admin email
.flatMap(submissionContact ->
Mono
.just(isSubmissionStatusNew(message))
.filter(Boolean::booleanValue)
.flatMap(isAdmin ->
forestClientApi
.get()
.uri("/districts/{districtCode}", details.getDistrictCode())
.exchangeToMono(clientResponse -> clientResponse.bodyToMono(
DistrictDto.class)
)
.doOnNext(district -> log.info(
"Loaded district details {} {}",
district.code(),
district.description()))
.map(DistrictDto::emails)
)
.defaultIfEmpty(submissionContact.getEmailAddress())
.map(mail -> Pair.of(submissionContact, mail))
)
.map(submissionContactPair ->
new EmailRequestDto(
details.getRegistrationNumber(),
details.getOrganizationName(),
submissionContactPair.getLeft().getUserId(),
submissionContactPair.getLeft().getFirstName(),
submissionContactPair.getRight(),
getTemplate(message),
getSubject(message, details.getOrganizationName()),
getParameter(
message,
submissionContactPair.getLeft().getFirstName(),
details.getOrganizationName(),
Objects.toString(details.getClientNumber(), ""),
String.valueOf(
message.parameters().get(ApplicationConstant.MATCHING_REASON)),
message.payload()
)
)
contactRepository
.findFirstBySubmissionId(message.payload())
.flatMap(submissionContact -> Mono.just(isSubmissionStatusNew(message))
.filter(Boolean::booleanValue)
.flatMap(isAdmin -> getDistrictEmailsAndDescription(details.getDistrictCode())
.map(districtInfo ->
new EmailRequestDto(
details.getRegistrationNumber(),
details.getOrganizationName(),
submissionContact.getUserId(),
submissionContact.getFirstName(),
districtInfo.getLeft(),
getTemplate(message),
getSubject(message, details.getOrganizationName()),
getParameter(message, submissionContact.getFirstName(),
details.getOrganizationName(),
districtInfo.getRight(),
Objects.toString(details.getClientNumber(), ""),
String.valueOf(message.parameters().get(ApplicationConstant.MATCHING_REASON)),
message.payload()
)
)
);
)
)
)
);
}

private Mono<Pair<String, String>> getDistrictEmailsAndDescription(String districtCode) {
return forestClientApi
.get()
.uri("/districts/{districtCode}", districtCode)
.exchangeToMono(clientResponse -> clientResponse.bodyToMono(DistrictDto.class))
.doOnNext(district -> log.info("Loaded district details {} {}",
district.code(),
district.description()))
.map(district -> Pair.of(district.emails(), district.description()));
}

private boolean isSubmissionStatusNew(MessagingWrapper<Integer> message) {
Expand Down Expand Up @@ -159,6 +145,7 @@ private Map<String, Object> getParameter(
MessagingWrapper<Integer> message,
String username,
String businessName,
String districtName,
String clientNumber,
String reason,
Integer submissionId
Expand All @@ -167,20 +154,22 @@ private Map<String, Object> getParameter(
.get(ApplicationConstant.SUBMISSION_STATUS)) {
case A -> approvalParameters(username, businessName, clientNumber);
case R -> rejectionParameters(username, businessName, clientNumber, reason);
default -> revisionParameters(username, businessName, submissionId);
default -> revisionParameters(username, businessName, submissionId, districtName);
};
}

private Map<String, Object> revisionParameters(
String username,
String businessName,
Integer submissionId
Integer submissionId,
String districtName
) {
return Map.of(
"userName", username,
"submission", submissionId,
"business", Map.of(
"name", businessName
"name", businessName,
"districtName", districtName
)
);
}
Expand Down

0 comments on commit 5fa147a

Please sign in to comment.