Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(BE:FSADT-745): updating mail template #491

Merged
merged 9 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public final class ApplicationConstant {

public static final String USERID_HEADER = "x-user-id";
public static final String USERMAIL_HEADER = "x-user-email";
public static final String USERNAME_HEADER = "x-user-name";
public static final BcRegistryDocumentRequestBodyDto
BUSINESS_SUMMARY_FILING_HISTORY =
new BcRegistryDocumentRequestBodyDto(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import java.time.LocalDate;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -29,7 +28,6 @@
import reactor.core.publisher.Mono;

@RestController
@Slf4j
@Tag(
name = "FSA Clients",
description = "The FSA Client endpoint, responsible for handling client data"
Expand Down Expand Up @@ -89,9 +87,10 @@ public Mono<ClientDetailsDto> getClientDetails(
example = "00000002"
)
@PathVariable String clientNumber,
@RequestHeader(ApplicationConstant.USERMAIL_HEADER) String userEmail
@RequestHeader(ApplicationConstant.USERMAIL_HEADER) String userEmail,
@RequestHeader(ApplicationConstant.USERNAME_HEADER) String userName
) {
return clientService.getClientDetails(clientNumber,userEmail);
return clientService.getClientDetails(clientNumber, userEmail, userName);
}

@GetMapping("/activeCountryCodes")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ public Flux<ClientListSubmissionDto> listSubmissions(
implementation = String.class,
example = "[email protected]"
)
),
@Header(
name = ApplicationConstant.USERNAME_HEADER,
description = "The name of the submitter who is making the submission",
schema = @Schema(
implementation = String.class,
example = "Joe Doe"
)
)
}
)
Expand All @@ -132,13 +140,14 @@ public Mono<Void> submit(
@RequestBody ClientSubmissionDto request,
@RequestHeader(ApplicationConstant.USERID_HEADER) String userId,
@RequestHeader(ApplicationConstant.USERMAIL_HEADER) String userEmail,
@RequestHeader(ApplicationConstant.USERNAME_HEADER) String userName,
ServerHttpResponse serverResponse) {
return Mono.just(request)
.switchIfEmpty(
Mono.error(new InvalidRequestObjectException("no request body was provided"))
)
.doOnNext(this::validate)
.flatMap(submissionDto -> clientService.submit(submissionDto,userId,userEmail))
.flatMap(submissionDto -> clientService.submit(submissionDto, userId, userEmail, userName))
.doOnNext(submissionId ->
serverResponse
.getHeaders()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
package ca.bc.gov.app.dto.client;

import java.util.Map;
import org.apache.commons.lang3.StringUtils;

public record ClientBusinessInformationDto(
String incorporationNumber,
String businessName,
String businessType,
String clientType,
String goodStanding,
String legalType
) {
public record ClientBusinessInformationDto(String incorporationNumber, String businessName,
String businessType, String clientType, String goodStanding, String legalType) {
public Map<String, Object> description() {
return Map.of(
"incorporation", incorporationNumber,
"name", businessName,
"businessType", businessType,
"clientType", clientType,
"legalType", legalType,
"goodStanding", goodStanding
);
"incorporation", StringUtils.isBlank(incorporationNumber) ? "" : incorporationNumber,
"name", StringUtils.isBlank(businessName) ? "" : businessName,
"businessType", StringUtils.isBlank(businessType) ? "" : businessType,
"clientType", StringUtils.isBlank(clientType) ? "" : clientType,
"legalType", StringUtils.isBlank(legalType) ? "" : legalType,
"goodStanding", StringUtils.isBlank(goodStanding) ? "" : goodStanding
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

public record ClientSubmissionDto(
ClientBusinessInformationDto businessInformation,
ClientLocationDto location
) {
public Map<String, Object> description() {
ClientLocationDto location) {
public Map<String, Object> description(String userName) {
Map<String, Object> descriptions = location.description();
descriptions.put("business", businessInformation.description());
descriptions.put("userName", userName);
return descriptions;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ public String legalName() {
return StringUtils.defaultString(clientName);
}

public Map<String, Object> description() {
public Map<String, Object> description(String userName) {
return
Map.of(
"userName", userName,
"number", clientNumber,
"name", legalName(),
"status", ClientStatusCodeEnum.valueOf(clientStatusCode),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public ChesCommonServicesService(
* @throws InvalidAccessTokenException if the authorization token is invalid or expired
* @throws InvalidRoleException if does not have the required role to perform the requested action
*/
public Mono<String> sendEmail(ChesRequest requestContent) {
public Mono<String> sendEmail(ChesRequest requestContent, String subject) {

if (requestContent == null) {
return Mono.error(new InvalidRequestObjectException("no request body was provided"));
Expand All @@ -91,7 +91,7 @@ public Mono<String> sendEmail(ChesRequest requestContent) {
ChesMailEncoding.UTF_8,
"[email protected]",
ChesMailPriority.NORMAL,
"Forest Client Application Confirmation",
subject,
null,
request.emailTo()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ public Flux<ClientNameCodeDto> listClientContactTypeCodes(int page, int size) {
*/
public Mono<ClientDetailsDto> getClientDetails(
String clientNumber,
String userEmail
String userEmail,
String userName
) {
log.info("Loading details for {}", clientNumber);
return
Expand All @@ -140,7 +141,7 @@ public Mono<ClientDetailsDto> getClientDetails(
.searchLegacy(document.business().identifier(), document.business().legalName())
.next()
.filter(isMatchWith(document))
.flatMap(sendEmail(userEmail))
.flatMap(sendEmail(userEmail, userName))
.flatMap(legacy -> Mono
.error(
new ClientAlreadyExistException(
Expand Down Expand Up @@ -312,20 +313,22 @@ private Predicate<ForestClientDto> isMatchWith(BcRegistryDocumentDto document) {
);
}

private Function<ForestClientDto,Mono<ForestClientDto>> sendEmail(String email) {
private Function<ForestClientDto,
Mono<ForestClientDto>> sendEmail(String email, String userName) {
return legacy ->
chesService
.buildTemplate(
"matched",
legacy.description()
legacy.description(userName)
)
.flatMap(body ->
chesService
.sendEmail(
new ChesRequest(
List.of(email),
body
)
),
"Client number application can’t go ahead"
)
)
.doOnNext(mailId -> log.info("Mail sent, transaction ID is {}", mailId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ public Flux<ClientListSubmissionDto> listSubmissions(
public Mono<Integer> submit(
ClientSubmissionDto clientSubmissionDto,
String userId,
String userEmail
String userEmail,
String userName
) {

return
Expand Down Expand Up @@ -165,15 +166,15 @@ public Mono<Integer> submit(
.location()
.contacts()
)
.flatMap(contact -> saveAndAssociateContact(locations, contact,
submission.getSubmissionId()))
/*.flatMap(contact -> saveAndAssociateContact(locations, contact,
submission.getSubmissionId()))*/
)
//Then grab all back as a list, to make all reactive flows complete
.collectList()
//Return what we need only
.thenReturn(submission.getSubmissionId())
)
.flatMap(submissionId -> sendEmail(submissionId, clientSubmissionDto, userEmail));
.flatMap(submissionId -> sendEmail(submissionId, clientSubmissionDto, userEmail, userName));
}

private Mono<SubmissionLocationContactEntity> saveAndAssociateContact(
Expand Down Expand Up @@ -208,21 +209,23 @@ private Mono<List<SubmissionLocationEntity>> saveAddresses(
private Mono<Integer> sendEmail(
Integer submissionId,
ClientSubmissionDto clientSubmissionDto,
String email
String email,
String userName
) {
return
chesService
.buildTemplate(
"registration",
clientSubmissionDto.description()
clientSubmissionDto.description(userName)
)
.flatMap(body ->
chesService
.sendEmail(
new ChesRequest(
List.of(email),
body
)
),
"Client number application received"
)
)
.doOnNext(mailId -> log.info("Mail sent, transaction ID is {}", mailId))
Expand Down
1 change: 1 addition & 0 deletions backend/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ ca:
- x-sub-id
- x-user-id
- x-user-email
- x-user-name
methods:
- OPTIONS
- GET
Expand Down
134 changes: 134 additions & 0 deletions backend/src/main/resources/templates/emailHead.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<head>
<meta charset="utf-8">
<!-- utf-8 works for most cases -->
<meta name="viewport" content="width=device-width">
<!-- Forcing initial-scale shouldn't be necessary -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- Use the latest (edge) version of IE rendering engine -->
<meta name="x-apple-disable-message-reformatting">
<!-- Disable auto-scale in iOS 10 Mail entirely -->
<title></title>
<!-- The title tag shows in email notifications, like Android 4.4. -->

<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link
href="https://fonts.googleapis.com/css2?family=Noto+Sans&display=swap"
rel="stylesheet">

<!-- CSS Reset : BEGIN -->
<style>

/* What it does: Remove spaces around the email design added by some email clients. */
/* Beware: It can remove the padding / margin and add a background color to the compose a reply window. */
html, body {
margin: 0 auto !important;
padding: 0 !important;
height: 100% !important;
width: 100% !important;
}

/* What it does: Stops email clients resizing small text. */
* {
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
}

/* What it does: Centers email on Android 4.4 */
div[style*="margin: 16px 0"] {
margin: 0 !important;
}

/* What it does: Stops Outlook from adding extra spacing to tables. */
table, td {
mso-table-lspace: 0pt !important;
mso-table-rspace: 0pt !important;
}

/* What it does: Fixes webkit padding issue. */
table {
border-spacing: 0 !important;
border-collapse: collapse !important;
table-layout: fixed !important;
margin: 0 auto !important;
}

/* What it does: Uses a better rendering method when resizing images in IE. */
img {
-ms-interpolation-mode: bicubic;
}

/* What it does: A work-around for email clients meddling in triggered links. */
*[x-apple-data-detectors], /* iOS */ .unstyle-auto-detected-links *,
.aBn {
border-bottom: 0 !important;
cursor: default !important;
color: inherit !important;
text-decoration: none !important;
font-size: inherit !important;
font-family: inherit !important;
font-weight: inherit !important;
line-height: inherit !important;
}

/* What it does: Prevents Gmail from displaying a download button on large, non-linked images. */
.a6S {
display: none !important;
opacity: 0.01 !important;
}

/* What it does: Prevents Gmail from changing the text color in conversation threads. */
.im {
color: inherit !important;
}

/* If the above doesn't work, add a .g-img class to any image in question. */
img.g-img+div {
display: none !important;
}

/* What it does: Removes right gutter in Gmail iOS app: https://github.com/TedGoas/Cerberus/issues/89 */
/* Create one of these media queries for each additional viewport size you'd like to fix */

/* iPhone 4, 4S, 5, 5S, 5C, and 5SE */
@media only screen and (min-device-width: 320px) and (max-device-width:
374px) {
u ~ div .email-container {
min-width: 320px !important;
}
}
/* iPhone 6, 6S, 7, 8, and X */
@media only screen and (min-device-width: 375px) and (max-device-width:
413px) {
u ~ div .email-container {
min-width: 375px !important;
}
}
/* iPhone 6+, 7+, and 8+ */
@media only screen and (min-device-width: 414px) {
u ~ div .email-container {
min-width: 414px !important;
}
}
</style>

<!-- CSS Reset : END -->

<!-- Progressive Enhancements : BEGIN -->
<style>
body {
font-family: 'BCSans', 'Noto Sans', Verdana, Arial, sans-serif;
font-weight: 400;
font-size: 16px;
line-height: 1.8;
}

a {
color: #0073E6;
}

p {
margin: 0px;
}
</style>
</head>
9 changes: 9 additions & 0 deletions backend/src/main/resources/templates/emailLogo.html

Large diffs are not rendered by default.

Loading